[英].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.