Forum Moderators: phranque
My current syntax is:
RewriteRule ^(dir1¦dir2¦dir3)/state\/city/?(.*)$ $1/template/C123/$2
My hope is that requests for
http://www.example.com/dir1/state/city/term
will rewrite to
http://www.example.com/template/C123/term
However, I'm getting extra segments appended to my URL. For example,
http://www.example.com/dir1/state/city/term
is rewriting as
http://www.example.com/template/C123/term/state/city/term
I also need this to work so that
http://www.example.com/dir1/state/city
http://www.example.com/dir1/state/city/
Will also redirect correctly. Now, using this code, they're going to
http://www.example.com/template/C123/state/city
I've tried a variety of constructions, but none are working correctly. Any ideas?
Thanks!
[edited by: jdMorgan at 12:06 am (utc) on Jan. 24, 2008]
[edit reason] example.com [/edit]
If external redirects were to be used, you would want to 301-redirect from the unfriendly format to the friendly format -- in order to remove previously-indexed unfriendly URLs from the search engines.
See the fourth post --and the recommendation-- in this previous thread [webmasterworld.com].
Jim
Most of the rewrites I have use this structure:
RewriteRule ^state\/city/?$ metro/C123
Thanks!
[edited by: jdMorgan at 12:07 am (utc) on Jan. 24, 2008]
[edit reason] example.com [/edit]
To avoid the Apache bug described in the document linked-to by the above-cited thread, you're generally better off to do all rewriting all-at-once in a single rule to any requested URL, rather than relying on a 'stack' of sequential rules to change bits and pieces at a time. So use the [L] flag on all of your rules, and make sure that neither the input URL to a rule, nor the output URL-path or file-path from that rule matches the pattern of any other rule (unless the first rule is an external redirect).
Some RewriteRule patterns, such as ".*" are pretty much guaranteed to trigger the apache bug. Others are less likely to do so, but I've never gone through the source code to analyze this.
Here's a thread with a solution to the Apache mod_rewrite bug [webmasterworld.com]. But I don't even use that code because it's complex and difficult to maintain; I wrote that code mostly as a proof-of-concept.
Jim