bobsoap
bobsoap

Reputation: 5104

htaccess redirect catchall

I need to redirect a directory, and all subdirectories and files in that directory, to the same location (root). So anyone who tries to visit /old, /old/folder, /old/other-folder/xy/page.php, or anywhere else within the 'old' folder, should be redirected to the root domain.

So far, I have this:

Redirect 301 ^/old/.*$ /

Is this the best way of doing it, or would it be better to use (.*) instead of .*? What is the difference between the two?

Or - should I use a RewriteRule instead of a Redirect like above? If so, why?

Thank you!

Upvotes: 0

Views: 1748

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

The Redirect directive doesn't use regular expressions. It connects 2 path nodes together, which isn't exactly what you want. You can try using the RedirectMatch directive instead:

RedirectMatch 301 ^/old/ /

Upvotes: 1

Igor
Igor

Reputation: 1855

You can try this

RewriteEngine On
RewriteBase /
RewriteRule ^old/?(.*) /$1 [R=301,NC,L]

If you just want to redirect every old page to homepage/root(I'm not sure exactly what you want) than you can replace last rewriterule with

RewriteRule ^old/.* / [R=301,NC,L]

Upvotes: 0

Related Questions