Forum Moderators: phranque
I'm trying to do the following with mod_alias:
RedirectMatch permanent "^/foo.*" [bar.com...]
The problem is, whatever comes after /foo gets concatenated onto the resulting URL. I don't want this, and based on the documentation for mod_alias, I wouldn't expect this behavior unless I did this:
RedirectMatch permanent "^/foo(.*)" [bar.com$1...]
How can I accomplish the simple redirect without concatenation of the extended URL?
Thanks,
-aj
RewriteRule ^foo http://www.example.com/? [R=301,L] You need a trailing / after the host name, otherwise you get a second redirect to add it. You need to avoid that redirection chain.
The question mark also clears any appended query string data too.
This prevents problems such as exposing your internal script paths if internal rewrites are excuted before external redirects because of module execution order.
Again, this is not a very-common problem. But it's a whole lot easier to prevent trouble when your site is small and growing, rather than having to go back and rewrite a whole bunch of code on a big site when it outgrows the server and must be moved to one where mod_rewrite executes before mod_alias. It's just one less thing to worry about when you are under pressure to make a fast and seamless server upgrade...
Jim