[英]CodeIgniter's URL/URI regarding the www CNAME and index.php
我目前在我的.htaccess文件中有此文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
當我輸入不帶www前綴的域名時:
[我輸入URL欄=>最終結果]
example.com => http://www.example.com/ == GOOD!
如果我輸入:
www.example.com/register => http://www.example.com/register == GOOD!
但是當我輸入:
example.com/register => http://www.example.com/index.php/register == BAD!
如何刪除所有極端情況的index.php部分? (特別是最后一個...)
試試這個代碼
# First add the www to URL
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# The remove the index.php from URL
RewriteCond $1 !^(index\.php|ref_doc|media|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我想順序很重要
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.