Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Apache mod#u rewrite';www域的重定向问题_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Apache mod#u rewrite';www域的重定向问题

Apache mod#u rewrite';www域的重定向问题,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,正在尝试为重定向页面配置.htaccess mod_重写规则 对 有价值。这方面的访问规则是: RewriteCond %{HTTP_HOST} ^example.com RewriteCond %{REQUEST_URI} ^/?page1/?$ RewriteRule (.*) http://www.example.com/page2/ [R=301,L] RewriteRule ^([^/]*)/$ index.php?s_page=$1 [L] 如果我发送get查询:“get”,则此

正在尝试为重定向页面配置.htaccess mod_重写规则 对

有价值。这方面的访问规则是:

RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]

RewriteRule ^([^/]*)/$ index.php?s_page=$1 [L]
如果我发送get查询:“get”,则此规则是正确的

但如果我尝试为域www.example.com编写其他规则,例如:

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
重定向无法正常工作。如果我尝试发送查询:“GET”,那么首先,浏览器会发送第一个查询“GET”,服务器对此查询的应答状态为“301永久移动”(并且服务器会发送html页面作为第一个查询的应答)。然后,浏览器发送第二个查询“GET”(服务器再次发送html页面)。 我需要的条件和规则,同样适用于查询与域的www和查询没有域的www前缀


顺便说一句,对不起英语。

您不需要为
www
域设置新规则。只需调整正则表达式:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^page1/?$ http://www.example.com/page2/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?s_page=$1 [L,QSA]

是的,它的格式更紧凑,工作原理也很相似。但是,类似地,当我在浏览器中键入“”时,它会发送两个GET查询,第一个是带有答案标题的“GET”:
“缓存控制最大年龄=0连接保持活动内容长度243内容类型文本/html;charset=iso-8859-1日期周二,2015年1月13日14:50:50 GMT到期周二,2015年1月13日14:50:50 GMT保持活动超时=5个位置http://www.example.com/page2/ 服务器Apache
“和正文的是请求的html页面内容。然后,browser send的第二个查询,正如我之前写的。嗯。。。也许这是正确的重定向工作?我认为浏览器不应该只发送一个查询,而应该只从服务器检索一个页面内容。
http://www.example.com/page1
将使用
R=301重新定向到
http://www.example.com/page2
。所以,如果您试图打开
http://www.example.com/page1
。但是如果您访问
http://www.example.com/page2
它应该只是浏览器中的单个GET请求。