我有一个在730ne.cz和www.730ne.cz上运行的OpenShift Python应用程序,我希望www版本重定向到非www。
我添加了wsgi / .htaccess,内容如下:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
但是,这也以无限重定向循环结束http://www.730ne.cz/application/application/application/application ...
所以我尝试了以下几个:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
和
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.730ne.cz [NC]
RewriteRule ^(.*)$ http://730ne.cz/ [R=301,L]
和
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.730ne.cz
RewriteRule ^(.*)$ http://730ne.cz/ [R=301,L]
但我得到的只是:
$ LANG=C wget http://www.730ne.cz/
--2015-03-12 21:40:13-- http://www.730ne.cz/
Resolving www.730ne.cz (www.730ne.cz)... 54.226.71.16
Connecting to www.730ne.cz (www.730ne.cz)|54.226.71.16|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.730ne.cz/ [following]
--2015-03-12 21:40:13-- http://www.730ne.cz/
Reusing existing connection to www.730ne.cz:80.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.730ne.cz/ [following]
--2015-03-12 21:40:13-- http://www.730ne.cz/
Reusing existing connection to www.730ne.cz:80.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.730ne.cz/ [following]
我做错了什么?如何正确地做到这一点?
答案 0 :(得分:1)
我在OpenShift上托管的WordPress blog遇到了同样的问题,我使用以下 .htaccess 规则修复了它:
RewriteEngine On
RewriteBase /
# www to non-www
RewriteCond %{HTTP_HOST} ^www.subinsb.com$
RewriteRule (.*) http://subinsb.com:80/$1 [R=301,L]