[英]htaccess rewrite index.php and redirect if without www
我的網站 url 是 www.site.com
如果用戶訪問 = site.com 我需要在 301 中重定向到 www.site.com
如果用戶訪問 = www.site.com/index.php/asd 我需要在 301 中重定向到 www.site.com/asd
如果用戶訪問 = site.com/asd 我需要在 301 中重定向到 www.site.com/asd
.htaccess 文件中的所有這些條件都可能嗎? 有人可以幫助我嗎? :)
謝謝;)
在 .htaccess 文件中嘗試以下規則:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s/index.php [NC]
RewriteRule ^index.php/(.*)$ /$1 [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,NC]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.