I was using something like this…
RewriteRule here/(.*) http://www.there.com/$1 [R=301,L]
but couldn’t get it to work
So I used this…
redirect 301 /here http://www.there.com
and it worked fine.
Can someone explain the difference?
Do you need both?
Also… how do I exclude paths from the redirect?
Like…
redirect 301 all…
redirect 301 /here http://www.there.com
but
/here/stayhere.html
Thanks
RewriteRule is handled by Apache’s mod_rewrite, while Redirect is handled by mod_alias. No, you don’t need both.
Your RewriteRule (which uses regex) will not match
/here(but will match such paths as/here/foo.html) because it is looking for a slash immediately after. You can make that optional by using a question mark:Now that will have the same effect as your Redirect. RewriteCond can be added to exclude certain paths:
Note that some servers do not have mod_rewrite turned on by default. If adding
RewriteEngine onto your configuration does not fix the problem and you cannot switch mod_rewrite on, at least mod_alias provides the RedirectMatch directive, which may be good enough: