Kivylius
Kivylius

Reputation: 6567

Redirection everything to index.php

I wan't to redirect everything to index.php exepept if a file or directory exists. I try'd a few ways from Google, but that really slowed the website down and don't really work so i amused that i got things wrong.

So URL like this:

    `site.com/Projects/S01/ -> site.com/Projects/S01/index.php (original)`
    `site.com/Projects/GE5/ -> site.com/Projects/GE5/index.php (original)`
    `site.com/Projects/     -> site.com/index.php`
    `site.com/Websites/     -> site.com/index.php`
    `sits.com/Testifcate/   -> site.com/index.php`

Whats the fastest way of doing this? All the methods I try'd are really slow. Thanks you. Files such as main.css are really slow at loading also, maybe those files don't go true the check to make it faster? What the best way to go about this?

Upvotes: 0

Views: 264

Answers (3)

Michael Leaney
Michael Leaney

Reputation: 751

Try the following:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f # ensures it's not a file
RewriteCond %{REQUEST_FILENAME} !-d # ensures it's not a directory
RewriteRule . index.php [L,QSA] # . matches all, and routes to index.php if the above conditions do not match

Upvotes: 1

Shane Fright
Shane Fright

Reputation: 385

This is my rewrite rule that does just that:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Upvotes: 2

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

Does this work for you:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^$ http://domain.com/index.php [L,R=301]

I Hope it helps

Upvotes: 0

Related Questions