Forum Moderators: phranque
(incorrect)
boards/pci-express-backplanes?view=product&product_id=3311&layout=backplane
and what I need is:
boards/backplanes?view=product&product_id=3311&layout=backplane
so basically I need to replace "pci-express-backplanes" with "backplanes" in these URLs (there are quite a few).
Thanks for any assistance!
Assuming that this code goes into your example.com/.htaccess file:
RewriteCond %{QUERY_STRING} ^view=product&product_id=[0-9]+&layout=backplane
RewriteRule ^boards/pci-express-backplanes$ http://example.com/boards/backplanes [R=301,L]
Do not use character-escaping except within regular-expressions patterns, and then only when actually required. The characters which need to be escaped are those which have special meaning to the regular-expressions matching engine, and those are listed in the Apache mod_rewrite documentation. Note that these escaping rules (POSIX 1003.2) differ from those used in PERL, PHP, etc., which use PCRE.
Jim
There is also the possibility that some new version of the code interpreter (e.g. mod_rewrite) might be released in the future -- One that is coded according to the documentation, but does not allow the same liberties to be taken with the coding style as did the older version. If that happened, your code would break. You'd have to go back and edit the code on your server -- or perhaps on dozens, hundreds, or even thousands of servers...
As a result, the code I post here is as close to being "perfect" according to the documentation as I can make it -- I take no liberties with 'style' of any kind.
Jim
As mentioned earlier, I am reviewing the mod_rewrite docs online and hope to gain understanding.
One thing that I do find amusing is that I was using the redirect tool provided through my host's cpanel and when I opened up the htaccess it generated, lo and behold, there were escape characters everywhere. So as you say, if they do decide to take a stricter stance on it, lots of people could have lots of issues.
And these are the reasons that I'm such a stickler for adhering to the documented syntax... I don't want to be responsible for spreading badly-written or inefficiently-coded rules.
I also studiously ignore all control panel features that I can do for myself. I've even found some of those features that once done, cannot be un-done -- The activation of custom .shtml error documents being one widespread example. Once turned on, they can't be removed in many control panels I've seen.
Jim