問題描述
我試圖讓我的 htaccess 重寫規(guī)則從 url 中刪除 index.php
并且還將 www.
請求重定向到非 www 版本.
I'm trying to get my htaccess rewrite rules to remove the index.php
from the url AND also redirect the www.
requests to the non-www version.
這是我的 htaccess,它可以很好地刪除 index.php:
This is my htaccess which works fine with removing the index.php:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我遇到了另一個關(guān)于如何刪除 www
部分的問題:
And I came across another question on how to remove the www
part:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
但我似乎無法讓他們一起玩得很好!任何意見/建議最感謝!
But I just cant seem to get them to play nicely together! Any advice/suggestions most appreciated!
推薦答案
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteEngine On
開始"重寫.RewriteCond
和 RewriteRule
成對工作.在這里,我們首先將用戶發(fā)送到非 www 版本,并清理 URL.
RewriteEngine On
"starts" rewriting. RewriteCond
and RewriteRule
work as pairs.
Here, we send user to non-www version first, and cleans URLs.
這篇關(guān)于Codeigniter htaccess 刪除 index.php 和 www的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!