Antony D'Andrea
Antony D'Andrea

Reputation: 1004

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

Upvotes: 0

Views: 5433

Answers (1)

rcpayan
rcpayan

Reputation: 535

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>

Upvotes: 1

Related Questions