How to redirect all pages to homepage?

Greetings,

I would like to redirect ALL pages and directories to my homepage, EXCEPT gif images and css files.

For example:
www.mysite.com/test/ > www.mysite.com/
www.mysite.com/index.php > www.mysite.com/
www.mysite.com/test/index.php > www.mysite.com/

I expected this to be simple but haven’t had much luck finding the right .htaccess code to do it. Let me know how this can be done.

Thanks

peppy,

That sounds very much like WP code which is something like:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? http://www.mysite.com/ [R=301,L]

I must say that this “protects” all existing files, not just gif and css files but index.php. I do not like redirecting in a LOOPY way from your home page to the domain which forces Apache to serve the home page again.

Regards,

DK

Thanks a lot kelynn! This seems to have done most of it.

I just added this little extra to the end of your code:

rewriteRule ^/index\\.php$ http://www.mysite.com/ [R=301,L]

This redirected the index.php file back to my homepage. Hopefully this will not cause any loops. It does work perfectly on my end now.

Thanks
Kind regards