Forum Moderators: phranque
I have been trying to rewrite some urls to static with no sucess.
www.mysite.co.uk/?cPath=21_ 386_392&sort=3a&products_id=124
[mysite.co.uk...]
but if it has shopping_cart.php in the string not to rewrite
thankz for any pointers
Welcome to WebmasterWorld!
If you are trying to create 'search engine friendly' static URLs, then it's likely you're trying to do this backwards.
First, change your script to output friendly static URLs on your pages, so visitors and search engines can see them. Then use mod_rewrite to detect those friendly URLs when they are requested from your server, and convert them back into the form needed to call your script.
Mod_rewrite acts after a request arrives at your server, and before any content is served or any scripts are invoked. Therefore, it can change incoming static URLs to the dynamic form needed to call your script, but it cannot change the URLs that appear on your site's pages.
For more information, see the documents cited in our forum charter [webmasterworld.com] and especailly see the mod_rewrite tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
[mysite.co.uk...]
Before we changed to this google had indexed our no friendly urls www.mysite.co.uk/?cPath=21_ 386_392&sort=3a&products_id=124
and now we are getting penilised for duplicate content
both url's work and both bring up the same content. Is there no way I can take the dynamic to 301 to the static If not how will I get it out of Google index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?cPath=([0-9_]+)[^&]*&products_id=([0-9]+)
RewriteRule ^/?$ http://www.example.co.uk/index.php/cPath/%1/products_id/%2? [R=301,L]
The code above will work in if:
li[]cPath and products_id are always present in the URLs that need to be redirected, and always in that order.
but if it has shopping_cart.php in the string not to rewrite
I did not understand this part, since it wasn't clear whether you are talking about the old or new URL. However, the code above will only rewrite requests for "/" as it is, so it appears to meet your requirement.
Jim
I do not understand what is wrong as if you shorten it for just catogaries to
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?cPath=([0-9]+)
RewriteRule ^/?$ [mysite.co.uk...] [R=301,L]
but this also is not 100% as it puts an extra cpathxx on the end of the url.
this url www.mysite.co.uk/?cPath=21 rewrites to
[mysite.co.uk...]
do not know why it has put?cpath=21 on the end
I have a few rules to write but once the first one is correct I can adapt on my own.
Thanks
RewriteRule ^index\.php/cPath/(21_22_93)/sort/3a [mysite.co.uk...] [R=301,L]
I am using the above rul which works fine but I do not want it to redirect url's that are in the form of
[mysite.co.uk...]
that is why I included the index.php in the string but it seems to ingnore that and redirect urls with shopping_cart.php in the url aswell
I do not understand I thought it would mach the whole URL.
Is there a way to get around this?