【问题标题】:Redirecting URLs with multiple parameters to clean URLs in .htaccess使用多个参数重定向 URL 以清除 .htaccess 中的 URL
【发布时间】:2015-03-19 05:52:01
【问题描述】:

我正在尝试重定向 .htaccess 中具有多个参数的 URL,例如:

http://www.example.com/index.php?p=product&id=10&parent=0 

到另一个域上的干净 URL,例如

http://example2.com/product/product10/

我相信我的常规重定向方法(在我创建的目录的索引文件中使用 PHP 标头)将无法正常工作,因为无法将 ? 放入目录名称中。

我做了一些小的 .htaccess,但没有转义参数或任何东西的经验,我能找到的唯一教程是只转义单个参数。

谁能指点一下?

【问题讨论】:

    标签: .htaccess redirect url-redirection url-parameters


    【解决方案1】:

    你可以在你的根.htaccess中使用它:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^p=([^&]+)&id=([^&]+) [NC]
    RewriteRule ^index\.php$ http://example2.com/%1/%1%2/? [R=302]
    

    当测试正常时将[R=302] 更改为[R=301]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 2016-06-11
      • 2014-08-10
      • 2016-01-09
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多