【问题标题】:PHP Variable to Wordpress shop pagePHP 变量到 Wordpress 商店页面
【发布时间】:2015-07-01 02:06:09
【问题描述】:

我有一个链接:

http://www.ignitionmarketing.co.za/products_promoDC.php?Product_Category=Corporate+Gifts

我希望它是:

http://www.ignitionmarketing.co.za/product-category/corporate-gifts/

我也尝试过正常的方式:

Redirect 301 /products_promoDC.php?Product_Category=Corporate+Gifts http://www.ignitionmarketing.co.za/product-category/corporate-gifts/

但它仍然停留在 404 页面上。

有人可以帮帮我吗?

补充说明:

我还有几个需要重定向的链接,例如:

/products_promoDC.php?Product_Category=Corporate+Clothing

/products_promoDC.php?Product_Category=Corporate+Clothing&Product_Subcategory=Shirts

新的 WordPress 商店也有相同的类别。

【问题讨论】:

  • 我已经取得了一些进展,我已重定向:ignitionmarketing.co.za/… TO:
  • 我已经取得了一些进展 我已经重定向了:ignitionmarketing.co.za/… TO:ignitionmarketing.co.za/shop/… 我现在需要做的就是通过页面传递参数(?Product_Category=Corporate+Clothing)或重写/corporate-clothing/的网址
  • 我找到了办法! RewriteCond %{QUERY_STRING} Product_Category=([^&]+) [NC] RewriteRule products_promoDC\.php product-category/%1/? [L,R=301] 现在我只需要将 (Corporate+Clothing) 重写为企业服装.....任何建议

标签: php regex wordpress .htaccess variables


【解决方案1】:

只是对解决方案的更好解释。也许你以后会遇到类似的问题。

我将我的“products_promoDC.php”重定向到 /product-category/ 所以变量/参数只加载在 (/product-category/Corporate+Clothing/) 后面,这仍然给了我一个 404 错误,因为加号 ( +) 在 URL 中。然后我简单地编写了一个 RewriteRule 将加号 (+) 转换为破折号!

比进行可能导致子类别出现问题的 RewriteMatch 容易得多。

RewriteRule "^([^+]*)\++([^+]*\+.*)$" /$1-$2 [N]
RewriteRule "^([^+]*)\++([^+]*)$" /$1-$2 [L,R=301]

RewriteCond %{QUERY_STRING} Product_Category=([^&]+) [NC]
RewriteCond %{QUERY_STRING} Product_Subcategory=([^&]+) [NC]
RewriteRule products_promoDC\.php product-category/%1/? [L,R=301]

我添加了第二行以加载我的子类别!

完美运行: http://www.ignitionmarketing.co.za/products_promoDC.php?Product_Category=Corporate+Gifts

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多