我目前在我的.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前缀的域名时:
[我输入网址栏=>它结束了什么]
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部分? (特别是最后一个......)
答案 0 :(得分:0)
试试此代码
# 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]
我认为排序很重要