How to redirect www to no-www on OpenShift properly?

空扰寡人 提交于 2019-12-08 11:15:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!