【问题标题】:redirect 301 with RewriteRule (for Joomla with params)使用 RewriteRule 重定向 301(对于带参数的 Joomla)
【发布时间】:2014-06-03 12:12:44
【问题描述】:

重定向 joomla 原生链接:

http://somesite.com/index.php?option=com_content&view=article&id=151&Itemid=40

=>

http://somesite.com/epr/active-requests

RewriteCond %{QUERY_STRING} option=com_content&view=article&id=151&Itemid=40
RewriteRule ^index\.php$ /epr/active-requests? [NC,R=301]

我需要使用附加 URL 参数重定向 joomla 文章 - RQNB:

链接 1:

http://somesite.com/index.php?option=com_content&view=article&id=151&Itemid=40&PARAM1=dummy&RQNB=1111&PG=REQ

=>

http://somesite.com/epr/active-requests?RQNB=1111

链接 2:

http://somesite.com/index.php?option=com_content&view=article&id=152&Itemid=40&PARAM1=dummy&RQNB=2222&PG=REQ

=>

http://somesite.com/dr/active-requests?RQNB=2222

请注意 Link1 和 Link2 指向不同的应用程序:

1)http://somesite.com/epr/active-requests?RQNB=1111

2)http://somesite.com/dr/active-requests?RQNB=2222

如何向 htaccess 添加参数条件?我需要另一行 RewriteCond 吗?谢谢。

编辑:

脏链接可能有一些其他不需要的参数(如 &PG=REQ),我只需要捕获 RQNB:

http://somesite.com/index.php?option=com_content&view=article&id=151&Itemid=40&RQNB=1111&PG=REQ

编辑2:

试过了,还是不行。。。 第一行:捕获 "&Itemid=40" 之后的所有内容 第二行:仅从第一行结果中捕获 &RQNB

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=151&Itemid=40(.*)$ [NC]
RewriteCond %{QUERY_STRING} ^RQNB=(.*)$ [NC]
RewriteRule ^index\.php$ /epr/active-requests?RQNB=%2 [NC,R=301]

【问题讨论】:

    标签: apache .htaccess mod-rewrite query-string


    【解决方案1】:

    您可以从查询字符串中捕获组,并使用 %1 引用它们

    类似的东西应该可以工作

    RewriteCond %{QUERY_STRING} option=com_content&view=article&id=151&Itemid=40&RQNB=(.*)$
    RewriteRule ^index\.php$ /epr/active-requests?RQNB=%1 [NC,R=301]
    

    如果您在 RQNB 之后有更多参数,那么以下应该可以工作:

    RewriteCond %{QUERY_STRING} ^RQNB=([^&]+) [NC,OR]
    RewriteCond %{QUERY_STRING} &RQNB=([^&]+) [NC]
    RewriteRule ^index\.php$ /epr/active-requests?RQNB=%1 [NC,R=301]
    

    【讨论】:

    • 谢谢,是的,我刚刚想出了相同的方法,但意识到链接可能有一些其他不需要的参数,请参阅编辑
    • 有没有办法在 option=com_content&view=article&id=151&Itemid=40 和 /epr/active-requests 之间建立关系?因为我会有其他旧链接指向(使用 RQNB 参数)。
    • 我不明白你的问题。您想重写哪些网址?去哪里?
    • 请看问题,我已经编辑了它,解释了link1和link2。
    • 如果我将使用您的最新版本的解决方案并且有多篇文章应该指向不同的应用程序 => 我无法区分 joomla 原生链接之间的关系 sef 链接
    【解决方案2】:

    基于this answer 我的工作解决方案是:

    RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=151&Itemid=40(.*)$ [NC]
    RewriteCond %{QUERY_STRING} (?:^|\b)(RQNB=[^&]+) [NC]
    RewriteRule ^index\.php$ /epr/active-requests?%1 [NC,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      相关资源
      最近更新 更多