Htaccess – redirecting all requests to domain root

.htaccessmod-rewrite

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. www.domain.com goes to www.domain.com/index.php

It'd be much nicer to have just www.domain.com, 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. www.domain.com and then redirect it to / eg. www.domain.com/dave.php -> www.domain.com – thus www.domain.com passes, but everything else is redirected… what's it actually doing and how to I get it to do what I want it to?

Best Answer

Just use it like this :

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

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

Related Topic