重写htaccess的老自从链接重写、链接、htaccess

2023-09-02 20:34:39 作者:ゞ绝緣じ☆ve—

我想重写所有的旧自从链接到一个新的网站。但我有麻烦,我需要重写URL的一部分。

链接看起来是这样的:

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

这改写适用于上面的链接:

 的RewriteCond%{REQUEST_URI} ^ /产品的详细信息 .PHP $
的RewriteCond%{QUERY_STRING} ^ CPATH = 3_72和放大器; products_id = 129安培; osCsid =(A-ZA-Z0-9 -_] +)$
重写规则^(。*)$ http://www.domain.com/apple/air.html? [R = 301,L]
 

但不会为工作:

  http://www.domain.com/product_info.php?cPath=3_72&products_id=129
 
codeigniter .htaccess链接到root CSDN问答频道

我的问题是,我想重写工作,无论在&放大器; osCsid = 6j3iabkldjcmgi3s1344lk1285 部分包括与否。

解决方案

我觉得你可以不指定结束分隔符($)实现这个

试试这个:

 的RewriteCond%{REQUEST_URI} ^ /产品的详细信息 .PHP $
的RewriteCond%{QUERY_STRING} ^ CPATH = 3_72和放大器; products_id = 129
重写规则^(。*)$ http://www.domain.com/apple/air.html? [R = 301,L]
 

如果不把$的正则表达式匹配字符串的结尾,你基本上是说:匹配以...开头的字符串,不管是什么来后

希望这有助于:)

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.

解决方案

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 :)