如何正确地将www重定向到OpenShift上的no-www? [英] How to redirect www to no-www on OpenShift properly?
问题描述
我有一个在730ne.cz和www.730ne.cz上运行的OpenShift Python应用程序,我希望将www版本重定向到非www.
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.
我添加了具有以下内容的wsgi/.htaccess:
I've added wsgi/.htaccess with the following content:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
但这也以无限重定向循环结尾 http://www.730ne.cz/应用程序/应用程序/应用程序/应用程序 ...
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]
并且:
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]
但是我得到的只是这个:
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?
推荐答案
我的 WordPress博客托管在OpenShift上,并使用以下 .htaccess 规则对其进行了修复:
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]
这篇关于如何正确地将www重定向到OpenShift上的no-www?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!