Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess-如何使;www";在一个可选的URL中?_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess htaccess-如何使;www";在一个可选的URL中?

.htaccess htaccess-如何使;www";在一个可选的URL中?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我尝试编写一个重定向,如果只使用http://和http://www. 这就是我得到的: RewriteCond %{REQUEST_URI} ^(.*)$example.com$ 这应该工作,无论URL如何开始,但我希望尽可能具体 我已经尝试过类似的方法,但没有成功: RewriteCond %{REQUEST_URI} ^(http:\/\/)$^(www\.)$example.com$ 如何编写一个只适用于http://和http://www.?使用以下方法: RewriteCond

我尝试编写一个重定向,如果只使用
http://
http://www.

这就是我得到的:

RewriteCond %{REQUEST_URI} ^(.*)$example.com$
这应该工作,无论URL如何开始,但我希望尽可能具体

我已经尝试过类似的方法,但没有成功:

RewriteCond %{REQUEST_URI}  ^(http:\/\/)$^(www\.)$example.com$
如何编写一个只适用于
http://
http://www.

使用以下方法:

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

  • (?:www\)?
    为您提供可选的
    www.
  • [NC]
    使匹配不区分大小写