【问题标题】:Removing part of a URL with .htaccess使用 .htaccess 删除部分 URL
【发布时间】:2020-12-21 20:28:26
【问题描述】:

我正在尝试使用我的 .htaccess 文件删除部分 URL。我有一些以前的重写工作。

网址是https://example.com/index.php?route=product/product&product_id=5062&manufacturer_id=57

我有 index.php?使用此规则删除,它正在工作

RewriteEngine On
RewriteBase "/"
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} (route.*)
RewriteRule "(.*)index.php" $1%1? [R=301,L]

现在有些网址的编号为manufacturer_id=1-4,我正在尝试删除它们。我现在得到一个内部重定向。

规则是

RewriteCond %{QUERY_STRING} (&manufacturer_id=[0-9]{1,4})

我怎样才能删除它而不会超出我的其他规则?

谢谢

【问题讨论】:

  • 为什么要删除manufacturer_id 参数?它在你的 php 代码中不重要吗?
  • 不,这不重要。它是 Opencart 1.5 url 规则的一部分。我有超过 20k 的重写规则,但在某些情况下,manufacturer_id 之类的东西违反了规则,并创建了太多重定向

标签: .htaccess url-rewriting


【解决方案1】:

将此规则放在 .htacces 顶部以删除查询参数:

RewriteCond %{THE_REQUEST} \?(.*&)?manufacturer_id=[^&]*&?(\S*)\s [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,NE,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多