htaccess的重定向所有请求的index.php重定向、htaccess、php、index

2023-09-02 10:05:00 作者:倾城一夜雪

所以,我想设置的东西,以便所有请求都通过index.php文件。

So I want to set things so that all requests go through index.php.

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

Some Google searches gave me this 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 /测试被视为www.domain / index.php的/测试,它的作用。

This works. But, I don't want it to run if I actually hit index.php. So I want www.domain/test to be treated as www.domain/index.php/test, which it does.

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

But if I hit www.domain/index.php/test in the browser, it should do the same thing but it redirects to a home folder somewhere.

此外,我看,我不希望这种重定向发生的CSS,JS和机器人。

Also I read that I wouldn't want this redirect to happen with css, js and robots.

如何让我的规则不是为的index.php做什么?

How do I make the rule not do anything for index.php?

推荐答案

这应该工作;

<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>
 
精彩推荐
图片推荐