htaccess – redirecting all requests to domain root

htaccess – redirecting all requests to domain root

I have a site that is no longer needed live and has a holding page setup to state that it’s no longer available. All requests to pages on the site (bookmarked or otherwise) need to be sent to this page which is the root index.php page, so I’m using some htaccess to redirect it accordingly.
I’m currently using this:
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ /index.php [R=302,NC,L]

which does the job, but adds index.php to the url – ie. goes to
It’d be much nicer to have just, but apparently I can’t do that using:
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ / [R=302,NC,L]

It gives a page not redirecting properly error in firefox.
I’d have expected the above to check to see if the REQUEST_URL isn’t / – ie. and then redirect it to / eg. -> – thus passes, but everything else is redirected… what’s it actually doing and how to I get it to do what I want it to?


Solution 1:

Just use it like this :

RewriteRule ^.+$ / [R=302,NC,L]

It will redirect all that don’t match / only to /.

Solution 2:

Is your problem solved? If not, have you tried:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . /index.php [L]


Related:  Force non-www and https via htaccess