简体   繁体   中英

.htaccess to redirect all requests to index.php

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

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>

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.

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.

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

How do I make the rule not do anything for 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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