.htaccess强制非www到www单页例外

时间:2013-04-02 16:31:56

标签: .htaccess exception redirect

我们已使用以下代码成功强制网站中的所有网页使用WWW:

##### Redirect non-www to www -- BEGIN
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/TEST_SITE/$1 [R=301,L]
##### Redirect non-www to www -- END

但我们的注册页面是一个例外,必须使用不包含WWW的URL。两天的测试和研究,我唯一可以产生的是错误和无限循环。有没有人建议将所有页面强制转换为WWW,除了这一页?

http://mysite.com/TEST_SITE/component/users/?view=registration

看起来它应该在一般的WWW重定向之前使用简单的重定向,但我在论坛中找不到类似的解决方案。我很感激任何想法......

2 个答案:

答案 0 :(得分:0)

#strip www from registration page
RewriteCond %{HTTP_HOST} ^(www\.)(.+)$
RewriteCond %{QUERY_STRING} ^view=registration$ [NC]
RewriteRule ^TEST_SITE/component/users/$ http://%2%{REQUEST_URI} [L,R=301,NC]

# prevent adding www to registration page
RewriteCond %{QUERY_STRING} ^view=registration$ [NC]
RewriteRule ^TEST_SITE/component/users/$ %{REQUEST_URI} [L,NC]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/TEST_SITE/$1 [R=301,L]

答案 1 :(得分:0)

有没有人建议将所有网页强制转换为WWW,除了这一页http://mysite.com/TEST_SITE/component/users/?view=registration是的,你可以。

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{QUERY_STRING} !view=registration
RewriteRule ^(.*) http://www.%{HTTP_HOST}/TEST_SITE/$1 [R=301,L]

添加新条件。