[英]mod_rewrite's redirect problems with www domain
Trying to configure .htaccess mod_rewrite rules for redirecting page http://www.example.com/page1/ to http://www.example.com/page2/ . 尝试配置.htaccess mod_rewrite规则以将页面http://www.example.com/page1/重定向到http://www.example.com/page2/ 。
Valuable .htaccess rules for this is: 有价值的.htaccess规则是:
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]
This rule works correct if I send get query: "GET http://example.com/page1/ ". 如果我发送获取查询,此规则的工作正确:“GET http://example.com/page1/ ”。
But if I try to write additional rule for domain www.example.com such as: 但是,如果我尝试为域www.example.com编写附加规则,例如:
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
Redirect doesn't work correctly. 重定向无法正常工作。 If I try send query: "GET http://www.example.com/page1/ " then, at first, browser sends first query "GET http://www.example.com/page1/ " and server's answer status is "301 Moved Permanently" for this query (and html page is sended by server as answer to the first query).
如果我尝试发送查询:“GET http://www.example.com/page1/ ”然后,首先,浏览器发送第一个查询“GET http://www.example.com/page1/ ”,服务器的回答状态是“301 Moved Permanently”用于此查询(并且html页面由服务器发送,作为对第一个查询的回答)。 Then, browser sends second query "GET http://www.example.com/page2/ " (and html page is sended again by the server).
然后,浏览器发送第二个查询“GET http://www.example.com/page2/ ”(并且服务器再次发送html页面)。 I need that conditions and rules works similarly for query with domain with www and query without domain's www prefix.
我需要条件和规则类似于查询域名使用www和查询没有域名的www前缀。
PS. PS。 sorry for english.
对不起英语。
You don't need a new rule for www
domain. 您不需要
www
域的新规则。 Just tweak the regex: 只需调整正则表达式:
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.