htaccess的 - 如何让" WWW"在URL可选? [英] htaccess - How to make the "www" in an URL optional?

查看:173
本文介绍了htaccess的 - 如何让" WWW"在URL可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试写一个,如果一个页面与访问的作品重定向仅的http:// ,也与 HTTP:// WWW。

I try to write a redirect that works if a page is accessed with only http:// and also with http://www..

这是我有:

RewriteCond %{REQUEST_URI} ^(.*)$example.com$

这应该工作无论怎样的URL开始,但我想应该尽可能具体。

This should work no matter how the URL begins, but I would like to be as specific as possible.

我已经尝试过这样的事情,但它没有工作:

I already tried something like this, but it didn't work:

RewriteCond %{REQUEST_URI}  ^(http:\/\/)$^(www\.)$example.com$

如何做我必须写一个重写条件适用于一个页面只有的http:// HTTP:// WWW

推荐答案

使用这样的:

RewriteCond %{REQUEST_URI} ^/?(?:www\.)?example\.com$ [NC]

  • (?:WWW \)?为您提供了一个可选的 WWW。
  • [NC] 使得比赛不区分大小写
  • (?:www\.)? gives you an optional www. group
  • [NC] makes the match case-insensitive

这篇关于htaccess的 - 如何让" WWW"在URL可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆