简体   繁体   English

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

[英].htaccess to redirect all requests to index.php

So I want to set things so that all requests go through index.php. 所以我想进行设置,以便所有请求都通过index.php。

Some Google searches gave me this mod_rewrite 一些Google搜索给了我这个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>

This works. 这可行。 But, I don't want it to run if I actually hit index.php. 但是,如果我真的命中index.php,我不希望它运行。 So I want www.domain/test to be treated as www.domain/index.php/test, which it does. 因此,我希望将www.domain / test当作www.domain / index.php / test来处理。

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

Also I read that I wouldn't want this redirect to happen with css, js and robots. 我还读到我不希望这种重定向在CSS,JS和机器人中发生。

How do I make the rule not do anything for index.php? 如何使规则对index.php不执行任何操作?

This should work; 这应该起作用;

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM