How to redirect www to no-www on OpenShift properl

2019-04-17 05:41发布

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条回答
该账号已被封号
2楼-- · 2019-04-17 06:20

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] 
查看更多
登录 后发表回答