Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule Disaster

         

Roswellb

1:32 pm on Sep 2, 2010 (gmt 0)

10+ Year Member



This is the original URL, tasmarkt.nl/index.php?id=22&tx_ttproductsv2_pi1[49][showFrom]=11&cHash=363aa80985

which I am hoping to transform into tasmarkt.nl/22/11/363aa80985

Preferably I wanted to make static rewriterules for each specified URL since I don't have to deal with a lot of URL'.
In that case i would, for example, transform tasmarkt.nl/index.php?id=22&tx_ttproductsv2_pi1[49][showFrom]=11&cHash=363aa80985 into (example) tasmarkt.nl/tas/kleur/vorm

So far I've ended up with the following;

RewriteRule ^([0-9]+)/([0-9]+)/([0-9a-z]+)/$ /index.php?id=$1&tx_ttproductsv2_pi1[49][showFrom]=$2&cHash=$3 [R=301,NC,L]

However this resulted in absolutely nothing happening on an Apache 2.2.8.

jdMorgan

3:09 pm on Sep 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you request "http://tasmarkt.nl/22/11/363aa80985/" from your server (note the required trailing slash), your rule will rewrite that to your script and the script will deliver page content. That is what this rule does.

mod_rewrite cannot be used to "change the URLs" published on your pages. If you wish to change your URLs, then edit the links on your pages to change them, or modify the script that produces them. PHP's preg_replace function may come in handy for this. This preg_replace should be the "mirror image" of the function of your rewriterule; it should take the dynamic query parameters used to access your database and re-arrange them into the static "search-engine-friendly" URL format that you are seeking to publish.

After changing the links on your pages, your mod_rewrite rule will then come into play, delivering requests for the new links to your script.

After getting that part working, you may wish to add another rule to speed up search engines' re-indexing of your new URLs. For more information, see the thread Changing Dynamic URLs to Static URLs [webmasterworld.com] in our Apache Forum Library.

Jim