簡體   English   中英

.htaccess將www重定向到非www不起作用

[英].htaccess redirect www to non-www not working

對於.htaccess編輯或正則表達式,我幾乎一無所知。 為了使我的網站從www版本重定向到non-www版本,我所做的就是遵循以下發布的答案:

將www重定向到非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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM