Forum Moderators: phranque
RewriteRule example-(.*)\.htm$ example.php?view=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example\.php\?view=([^&]+)\ HTTP/
RewriteRule ^example\.php$ http://www.example.com/z_index-%1\.htm? [R=301,L]
so my URL example.php?view=checkout rewrites to example-checkout.htm
But then I had to make it so that example.php?view=checkout&step=2 rewrites to example-checkout-2.htm. I tried the following:
RewriteRule example-(.*)\.htm$ example.php?view=$1 [L]
RewriteRule example-(.*)-([0-9]+)\.htm$ examplephp?view=$1&step=$2 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example\.php\?view=([^&]+)\ HTTP/
RewriteRule ^example\.php$ http://www.example.com/z_index-%1\.htm? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example.php\?view=([^&]+)&step=([^&]+)\ HTTP/
RewriteRule ^example\.php$ http://www.example.com/z_index-%1-%2\.htm? [R=301,L]
This however ends up rewriting it to: example-checkout.htm?view=checkout&step=2
Can anyone help?
[edited by: jdMorgan at 2:55 pm (utc) on Aug. 3, 2006]
[edit reason]
[1][edit reason] example.com [/edit] [/edit][/1]
I'd suggest:
# Internally rewrite .htm URL request to script
RewriteRule example-([^-]+)-([0-9]+)\.htm$ examplephp?view=$1&step=$2 [L]
RewriteRule example-([^-]+)\.htm$ example.php?view=$1 [L]
#
# Externally redirect requested dynamic URLs to static equivalents, to clean up SE listings
@
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example.php\?view=([^&]+)&step=([^&]+)\ HTTP/
RewriteRule ^example\.php$ http://www.example.com/z_index-%1-%2\.htm? [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example\.php\?view=([^&]+)\ HTTP/
RewriteRule ^example\.php$ http://www.example.com/z_index-%1\.htm? [R=301,L]
General advice: Avoid the use of the greedy and promiscuous ".*" patterns whenever possible; Use a more-specific pattern. Order your rules from most-specific and longest to least-specific and shortest.
Jim
I am still seeing similar results.
So this works: example.php?view=checkout rewrites to example-checkout.htm
However, when I am on this page: example-checkout.htm and click the "next step" button in the checkout process, which has a URL of example.php?view=checkout&step=2
it gets rewritten to:
example-checkout.htm?view=checkout&step=2
hence making the checkout process not work.
Similarily: example.php?view=shop&cat_id=100 gets rewritten to example-shop-100.htm perfectly.
but when going to the next page of results where the URL is: example.php?view=shop&cat_id=100&start=8&page=2
it gets rewritten to
example-shop-100.htm?view=shop&cat_id=100&start=8&page=2
So if a portion of the querystring is already contained in the proceeding URL it breaks.
Thanks.
So it appears that the problem is not with the rules above, but with some other code that is interfering. Do you have additional rewrites/redirects in httpd.conf, or in any other .htaccess files in other directories?
Either that, or the rules above and the code that you actually have on your site are not the same.
There is a much bigger problem, though. You should not be using mod_rewrite to redirect the dynamic URLs to static equivalents *except as a way to correct old search engine listings*. All conversion of dynamic to static URLs should be done inside your shopping cart script (using preg_replace, for example).
Maybe this primer [webmasterworld.com] in our forum library will be helpful. You're likely familiar with much of it, but look for details...
Jim
i.e.: example.com?view=test would get rewritten, but example.com?view=test&step=1&var=2 wouldn't.
Thanks.
The second rule will accept only requests with a query of "view=<parm>&step=<parm>"
The third rule will accept only requests with a query of "view=<parm>"
Neither rule will accept additional parameters, as a result of the test for <space>/HTTP at the end.
So there is a "logical disconnect" between what the code above will do, and the results that you are reporting.
Therefore, the problem appears to be with *other* rewrite or redirect code, or with your PHP code. But if you have no time to review the references I cited in order to better understand the problem, then I'm sorry but I can't do much more for you.
Jim