Thomas Clayson
Thomas Clayson

Reputation: 29925

htaccess redirect question

I have this:

RewriteRule ^([^/]+\.html)         /index.php             [L]
RewriteRule ^([^/]+\.htm)          /$1l               [R=301,L]

Which redirects all .html files to index.php and all .htm files to their .html equivalent.

What I need now is the same thing but to redirect all directories to /index.php too (with the [L] style redirect.)

Ie if I put in:

http://mywebsite.com/a/folder.html

or

http://mywebsite.com/afolder

it needs to redirect to /index.php but as if the URL in the address bar is the acctual address.

I can't figure out how to do it. I've tried many different variations with (.*)s and [^/]s and can't figure out anything. I just keep getting internal server errors and 404s.

Any ideas?

Thank you.

Upvotes: 1

Views: 59

Answers (1)

Ian Wetherbee
Ian Wetherbee

Reputation: 6109

RewriteRule ^(.+)/(.*) /index.php [L]

Any request with at least one slash will be passed to index.php instead.

Upvotes: 1

Related Questions