0
votes

What I want to do is redirect all non exist URLS to index.php?q=%URL%, for example:
www.example.com/ggg will redirect to www.example.com/index.php?q=ggg

however, I want the address bar to still show www.example.com/ggg

what I got so far is this:

Options +FollowSymLinks
RewriteEngine On

# redirect all requests to non-existing resources to special handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/? /index.php?q=$1 [L,NC,R]

but it keeps changing the address bar and also I'm not sure it actually works all the time.

any suggestions? Thanks

1
Actially I want to redirect all error pages, not just 404. thanksuser3720583

1 Answers

3
votes

Remove the R flag if You want to rewrite your error pages to index.php.

Options +FollowSymLinks
RewriteEngine On

# redirect all requests to non-existing resources to special handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?q=$1 [L,NC]