[英].htaccess redirect www to non-www not working
对于.htaccess编辑或正则表达式,我几乎一无所知。 为了使我的网站从www
版本重定向到non-www
版本,我所做的就是遵循以下发布的答案:
但是,得到的是,如果输入www.example.com
,则会得到:
example.com/example.com/
和我的网站上出现404错误
这是我的.htaccess文件:
#Adjust default time zone
SetEnv TZ America/Toronto
#Begin redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>
# END Google Analytics Integration
有人可以启发我我做错了什么吗?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
也就是说,检查HTTP_HOST是否包含www,如果包含,则重定向到附加了request_uri的非www。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.