.htaccess将所有请求重定向到index.php

时间:2013-05-23 16:23:16

标签: apache .htaccess

所以我想设置所有请求通过index.php。

一些谷歌搜索给了我这个mod_rewrite

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !(index\.php|public|css|js|robots\.txt) 
    RewriteRule ^ index.php [L,QSA]
</IfModule>

这很有效。但是,如果我真的点击index.php,我不希望它运行。 所以 我希望www.domain / test被视为www.domain / index.php / test,它确实如此。

但是如果我在浏览器中点击www.domain / index.php / test,它应该做同样的事情,但它会重定向到某个地方的主文件夹。

另外,我读到我不希望这种重定向发生在css,js和robots上。

如何使规则不对index.php做任何事情?

1 个答案:

答案 0 :(得分:1)

这应该有用;

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|public|css|js|robots\.txt|test) 
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
相关问题