mod_rewrite 的 www 域重定向问题
mod_rewrite's redirect problems with www domain
正在尝试为重定向页面配置 .htaccess mod_rewrite 规则
http://www.example.com/page1/ to http://www.example.com/page2/。
有价值的 .htaccess 规则是:
RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
RewriteRule ^([^/]*)/$ index.php?s_page= [L]
如果我发送 get 查询:"GET http://example.com/page1/",此规则将正常工作。
但是如果我尝试为域 www.example.com 编写附加规则,例如:
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
重定向无法正常工作。如果我尝试发送查询:"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). Then, browser sends second query "GET http://www.example.com/page2/"(服务器再次发送 html 页面)。
我需要条件和规则对于带有 www 的域查询和没有域的 www 前缀的查询类似地工作。
PS。对不起英语。
您不需要 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= [L,QSA]
正在尝试为重定向页面配置 .htaccess mod_rewrite 规则 http://www.example.com/page1/ to http://www.example.com/page2/。
有价值的 .htaccess 规则是:
RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
RewriteRule ^([^/]*)/$ index.php?s_page= [L]
如果我发送 get 查询:"GET http://example.com/page1/",此规则将正常工作。
但是如果我尝试为域 www.example.com 编写附加规则,例如:
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{REQUEST_URI} ^/?page1/?$
RewriteRule (.*) http://www.example.com/page2/ [R=301,L]
重定向无法正常工作。如果我尝试发送查询:"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). Then, browser sends second query "GET http://www.example.com/page2/"(服务器再次发送 html 页面)。 我需要条件和规则对于带有 www 的域查询和没有域的 www 前缀的查询类似地工作。
PS。对不起英语。
您不需要 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= [L,QSA]