Forum Moderators: phranque

Message Too Old, No Replies

Redirecting an URL in a context of rewritten dynamic URL

redirection 301 mod_rewrite

         

lruellan

2:02 pm on Apr 11, 2007 (gmt 0)

10+ Year Member



Dear fellow webmasters,

Here is my problem:

My htaccess file starts with a bunch of redirect 301 commands, and ends with a set of url rewriting rules.

I have been using mod_rewrite to rewrite my dynamic URL into a static looking URL. For instance, the url /club/crobar/ is actually rewritten by apache into guide.php?category=club&name=crobar

Now, I need to redirect an old URL to the new location of the page (namely: /club/studio_mezmor/ ) because the name of the place has changed.

So I added to my htaccess: redirect 301 /club/crobar/ [......]

The problem is when I look at my logs, I see that the agent has followed the redirection but has also applied the rewriting rule to the redirected URL, which gives:
[......]

Is there a command similar to [L] that could be added to a redirect 301 in order to stop the server looking for other rules or command?

Thank you for your assistance with this.

Lothaire

jdMorgan

2:19 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem here is that you are mixing mod_alias and mod_rewrite directives. Since the server configuration determines which of these modules will parse your .htaccess file first, and since this setting may not be under your control and/or may differ from host to host, it is better to use all mod_rewrite or all mod_alias directives when the order of execution must be controlled.

Each Apache module in turn reads your .htaccess file in the order specified by the server configuration, and applies only those directives that it understands. Therefore, only directives for the same module are executed in the order that you write them in your .htaccess file.

To clarify, the likely cause is that your internal rewrite (mod_rewrite) is being applied first, and the the external redirect (mod_alias) is invoked, thus exposing your internal script URL to the client.

So, I'd recommend that you re-code your redirect using mod_rewrite, and place it in the first section with your other redirects -- above the internal rewrites. That will likely make your problem go away.

Jim

lruellan

8:18 pm on Apr 11, 2007 (gmt 0)

10+ Year Member



I got it! Thank you so much for your help. It makes total sense. I dont know why I couldnt come with this solution on my own...

Lothaire