Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch

Concatenating problem

         

ajcoon

6:50 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



Hello,

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

Samizdata

9:27 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think this should do the trick:

RedirectMatch 301 ^/foo http://www.example.com/

Anything at all that starts with "/foo" should be redirected to example.com root.

...

ajcoon

9:35 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



Hello,

Tried this (essentially removing the .* from the LHS of my original configuration) and had the same result, unfortunately.

Thanks,
-aj

g1smd

9:37 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I always use RewriteRule so never meet that issue.

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.

Samizdata

10:04 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



had the same result, unfortunately

As our esteemed moderator often says (I paraphrase):

"Completely flush your browser cache before testing any changes."

It seemed to work fine here on a quick test.

...

ajcoon

10:06 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



That did the trick...thanks!

-aj

g1smd

10:13 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you also got any stuff using Mod_Rewrite?

Be aware not to mix Mod_Rewrite and Mod_Alias stuff in the same file.

Samizdata

10:26 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Be aware not to mix Mod_Rewrite and Mod_Alias stuff in the same file

I certainly wouldn't want to mix them, but I have no problem using them in the same file.

I have RedirectMatch calls before RewriteEngine On on several sites.

Apologies if I misundertood you.

...

g1smd

10:47 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Execution order depends on the reverse order of module loading in the httpd.conf file... not on the order you list the rules in your file.

jdMorgan

8:10 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... and can change if you switch hosts -- It's not common, but does happen, and can cause trouble. Therefore, if any execution-order dependencies exists, it's best to use only mod_rewrite if you use any mod_rewrite.

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

g1smd

10:32 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



More details in posts over there: [webmasterworld.com...]

Samizdata

11:46 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks to both of you for the explanations (and welcome back Jim).

This is a potential problem I will be eliminating from all my sites.

...