Question

I was wondering if it's possible to redirect all requests to files/directories that do not exist to index.php, and after that clean the url.

So when I go to www.example.com/test/1 I want it to be redirected (rewrote?) to www.example.com

I tried the following and it does correctly load index.php, but it still says www.example.com/test/1 in the URL bar...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

Of course I still want my css and js to load properly...

Was it helpful?

Solution

Try this. If I understand, you want to use this as a way of redirecting a 404 not found?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [R=301,L]

Or maybe this without index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top