【问题标题】:RewriteRule for article.php?id=1 to name-of-printer将 article.php?id=1 的 RewriteRule 改写为 name-of-printer
【发布时间】:2017-07-18 14:26:22
【问题描述】:

因此,我们最近获得了一个客户网站,该网站正在为我们的客户定制开发,它们基本上具有不友好的 URL “article.php?id=1”。我试图让他们对 SEO 友好,而在创建新 URL 时,我无法让他们的旧 URL 自动重定向到我刚刚创建的内容。

我尝试了以下方法,但没有成功:

RewriteEngine On
RewriteBase /

RewriteRule ^articulo.php?id=1$ "xerox-phaser-3020bi" [NC,R=301,L]
RewriteRule ^xerox-phaser-3260dni$ /articulo.php?id=2 [R=301,L]
RewriteRule ^xerox-phaser-33dn$ articulo.php?id=3 [L]

如您所见,我正在为每个产品(仅大约 38 个)手动创建 URL,并且由于该应用程序不打印 category.php?name=nameofcategory&article.php?id=1 我认为这是最好的方法友好的 URL。

我想要的是,当有人在我们的网站上点击 /article.php?id=1 产品时,他们会被带到友好的 URL,例如:/xerox-phaser-3260dni

谢谢!

编辑:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=1$ 
RewriteRule ^articulo\.php$ /xerox-phaser-3260dni/? [R=301,L]

此代码在访问友好 URL 时重定向但不显示页面。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    您的方法不起作用,因为您的网址包含? 之类的符号。您需要使用{QUERY_STRING}

    尝试以下方法:

    RewriteCond %{QUERY_STRING} article.php?id=1$ 
    RewriteRule (.*) /xerox-phaser-3260dni/? [R=301,L]
    

    不要忘记在重定向 URL 的末尾添加 ?,因为这是必要的,这样查询字符串就不会出现在 URL 的末尾。

    确保在测试之前清除缓存。

    【讨论】:

    • 很遗憾,此建议在访问友好 URL 时不会重定向或返回正确的页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 2012-11-09
    • 2014-10-03
    • 2011-07-28
    • 2021-08-31
    • 2022-11-20
    • 2020-04-09
    相关资源
    最近更新 更多