Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 346
andyface Avatar asked Mar 15 '11 10:03

andyface


1 Answers

Just use it like this :

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

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

like image 113
M'vy Avatar answered Sep 19 '22 14:09

M'vy