Forum Moderators: phranque
How many actions are shown in the Live HTTP Headers (an extension for Firefox) report?
Are there multiple redirects in a chain, or just one redirect?
You likely also want [R=301,L] rather than the 302 redirect you have now.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cgi-bin/store/[^/.]+\.cgi/[^\ ]*\ HTTP/
RewriteRule ^cgi-bin/store/([^/.]+)\.cgi(/.*)?$ http://www.example.com/$1$2 [R=301,L]
#
RewriteCond $1 !^cgi-bin$
RewriteCond $2 !^/store/[^/.]+\.cgi
RewriteRule ^([^/.]+)((/[^/.]+)*)$ /cgi-bin/store/$1.cgi$2 [L]
RewriteCond $1$2 !^cgi-bin/store/[^/.]+\.cgi
RewriteRule ^([^/.]+)((/[^/.]+)*)$ /cgi-bin/store/$1.cgi$2 [L]
RewriteCond $1 !^cgi-bin/store/[^/.]+\.cgi
RewriteRule ^(([^/.]+)((/[^/.]+)*))$ /cgi-bin/store/$2.cgi$3 [L]
Well, there were some regex problems and a possible infinite-loop in there...
Try:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cgi-bin/store/[^/.]+\.cgi/[^\ ]*\ HTTP/
RewriteRule ^cgi-bin/store/([^/.]+)\.cgi(/.*)?$ http://www.example.com/$1$2 [R=301,L]
#
RewriteCond $1 !^cgi-bin$
RewriteCond $2 !^/store/[^/.]+\.cgi
RewriteRule ^([^/.]+)((/[^/.]+)*)$ /cgi-bin/store/$1.cgi$2 [L]
I also removed unnecessary parentheses, removed unneeded escaping within the alternate-character-groups, and ordered the negative-match alternate-character groups with the most-likely-to-occur-characters first (for speed).
The exclusions on the second rule are necessary to prevent it looping on itself. I could be written more efficiently as
RewriteCond $1$2 !^cgi-bin/store/[^/.]+\.cgi
RewriteRule ^([^/.]+)((/[^/.]+)*)$ /cgi-bin/store/$1.cgi$2 [L]
or as
RewriteCond $1 !^cgi-bin/store/[^/.]+\.cgi
RewriteRule ^(([^/.]+)((/[^/.]+)*))$ /cgi-bin/store/$2.cgi$3 [L]
once you understand what the simpler-syntax version above is doing. They're all equivalent, with the second two versions only a bit more efficient. Use whichever you like.
> question regarding the first condition, near the end you have .cgi/[^\ ]*
The "[^\ ]*" subpattern says, "Match zero or more characters not equal to a space." Therefore, including the "/" ahead of that subpattern is neither necessary nor desirable.
If you think that somehow I never make errors, thanks. But I assure you that that is not the case... :)
That's why I/we must test. :)
So in this case, getting rid of that trailing slash requirement in both patterns is likely the correct approach.
the pattern for the URL-path in the RewriteCond %{THE_REQUEST} and the rewriterule should always be consistent.