Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule vs RedirectMatch

         

xxclixxx

8:32 pm on Feb 6, 2007 (gmt 0)

10+ Year Member



Hello All

I have a redirect match that works, but there are rewrite rules that happen after it that make the redirect all funky (it adds?/b-boardname/m-messagenumber/ to the end) When I do the same regexp with rewrite rule it no longer works.

Is there a way to tell RedirectMatch to not keep going (sorta like the L flag)? Or is there something special that RewriteRule needs for the regexp to work?

The URL:
/b-general/m-1139941776/

Should redirect to:

/m-1139941776/

What I'm using:

RedirectMatch ^/b-(.*)/m-(.*)/$ http://forum.example.com/m-$2/
RewriteRule ^/b-(.*)/m-(.*)/$ http://forum.example.com/m-$2/ [L]

[edited by: jdMorgan at 11:10 pm (utc) on Feb. 6, 2007]
[edit reason] Example.com [/edit]

jdMorgan

11:10 pm on Feb 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Redirect and RewriteRule directives belong to two different modules, and each module executes separately, in whatever order your server is configured to execute them. So there is no way for a mod_alias directive to tell a mod_rewrite directive not to execute. The solution is to use the same module for all internal rewrites and external redirects so that you can control the order and conditions of execution.

If your code is located in .htaccess, you should know that the path to the current directory will be stripped from the URL-path seen by RewriteRule. In simple terms, that means that the leading slash will not be present in the URL-paths referring to your top-level Web-accessible directory, so your pattern won't match. Try something like:


RewriteRule [b]^b-[/b]([^/]+)/m-([^/]+)/?$ http://forum.example.com/m-$2/ [R=301,L]

Jim