Rewrite htaccess old oscommerce links

萝らか妹 提交于 2019-12-23 04:52:54

问题


I am trying to rewrite all the old oscommerce links to a new website. But I am having trouble with part of the URL I need to rewrite.

The link looks like this:

http://www.domain.com/product_info.php?cPath=3_72&products_id=129&osCsid=6j3iabkldjcmgi3s1344lk1285

This rewrite works for the above link:

RewriteCond %{REQUEST_URI}  ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129&osCsid=([A-Za-z0-9-_]+)$
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]

But will not work for:

http://www.domain.com/product_info.php?cPath=3_72&products_id=129

My problem is that I want the rewrite to work no matter if the &osCsid=6j3iabkldjcmgi3s1344lk1285 part is included or not.


回答1:


I think you can achieve this by not specifying the closing delimiter ($)

Give this a try:

RewriteCond %{REQUEST_URI}  ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]

By not putting the $ at the end of the regex string you are basically saying: match any string that starts with ..., no matter what comes after

Hope this helps :)




回答2:


This should do the job just fine:

RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^product_info\.php$ http://www.domain.com/apple/air.html? [R=301,L]
  1. There is no need for separate condition RewriteCond %{REQUEST_URI} ^/product_info\.php$ -- this part can be (actually, SHOULD BE, for better performance) moved to RewriteRule.

  2. This is enough ^cPath=3_72&products_id=129 -- it tells "When query strings STARTS with ...". No need to include optional/non-important parameters osCsid=([A-Za-z0-9-_]+).

  3. This rule is to be placed in .htaccess file in website root folder. If placed elsewhere some small tweaking may be required.



来源:https://stackoverflow.com/questions/6746088/rewrite-htaccess-old-oscommerce-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!