问题
I have an OpenShift Python app running on 730ne.cz and www.730ne.cz and I want the www version to redirect to the non-www.
I've added wsgi/.htaccess with the following content:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
But that ended in infinite redirect loop too http://www.730ne.cz/application/application/application/application...
So I've tryed the following ones:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
And:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.730ne.cz [NC]
RewriteRule ^(.*)$ http://730ne.cz/ [R=301,L]
And:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.730ne.cz
RewriteRule ^(.*)$ http://730ne.cz/ [R=301,L]
But all I get is this:
$ 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]
What am I doing wrong? How to do this properly?
回答1:
I had this same problem with my WordPress blog hosted on OpenShift and I fixed it with the following .htaccess rule :
RewriteEngine On
RewriteBase /
# www to non-www
RewriteCond %{HTTP_HOST} ^www.subinsb.com$
RewriteRule (.*) http://subinsb.com:80/$1 [R=301,L]
来源:https://stackoverflow.com/questions/29020063/how-to-redirect-www-to-no-www-on-openshift-properly