【问题标题】:How to redirect in .htacces &Itemid=x to &Itemid=Y如何在 .htaccess & Itemid=x 中重定向到 Itemid=Y
【发布时间】:2012-09-01 19:34:49
【问题描述】:

你好,我有这个问题

我无法重定向 index.php?option=com_adsmanager&view=list&catid=8&Itemid=435 对此 index.php?option=com_adsmanager&view=list&catid=8&Itemid=565

catid=8 是我需要重定向所有 catid= 值的变量

我只需要将 &Itemid=435 更改为 &Itemid=565

我有这个代码

   RewriteEngine on
    RedirectMatch 301 ^(.+)\&Itemid=435$ $1&Itemid=565

我不知道怎么了 我需要所有 url 任何东西&Itemid=435 到 sameanything&Itemid=565

【问题讨论】:

  • 另一个选项是从:myurl/index.php/variable 到:myurl/index.php/clasificados/variable

标签: .htaccess mod-rewrite joomla joomla2.5 http-status-code-301


【解决方案1】:

另类

在index.php或Joomla的configuration.php顶部添加PHP Code下方!

它检查数字 catid 和 Itemid 请求,如果是 Itemid=435,它将使用 catid 和新的 Itemid 重定向 URL。随意根据您的需要修改代码!

if(isset($_GET['catid']) && is_numeric($_GET['catid']) && isset($_GET['Itemid']) && is_numeric($_GET['Itemid']))        
if($_GET['Itemid'] == 435)
{
    $catid    = $_GET['catid'];
    $location = "/index.php?option=com_adsmanager&view=list&catid=$catid&Itemid=565";
    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: '. $location);
}

答案 - 2

我假设您想要将URI-1 重定向到URI-2。

  1. index.php?option=com_adsmanager&view=list&catid=8&Itemid=435

  2. index.php?option=com_adsmanager&view=list&catid=8&Itemid=565

在mod_rewrite 下方,您可以将specific URI 重定向到其他specific URI。 只需在.htaccess 文件中添加以下规则即可。

<IfModule mod_rewrite.c>
 Options +FollowSymlinks
 RewriteEngine on
 RewriteCond %{QUERY_STRING} ^option=com_adsmanager&view=list&catid=8&Itemid=435$
 RewriteRule ^/?index\.php$ /index.php?option=com_adsmanager&view=list&catid=8&Itemid=565 [R=301,L]
</IfModule>

答案 - 3

如果您想处理带有'/index.php' 和'/' 的请求,请在.htaccess 中使用下面的内容。

<IfModule mod_rewrite.c>
 Options +FollowSymlinks
 RewriteEngine on
 RewriteCond %{QUERY_STRING} ^option=com_adsmanager&view=list&catid=8&Itemid=435$
 RewriteRule ^(.*)$ /index.php?option=com_adsmanager&view=list&catid=8&Itemid=565 [R=301,L]
</IfModule>

注意:不要在单个 .htaccess 文件中同时使用这两个代码。

【讨论】:

  • 感谢 Mayur 但是当 x 是数字时,我有很多 &catid=x 不是正确的代码
  • 您可以使用PHP 代码来执行这样的301 redirection,我添加了sample code,这可能会导致您获得想要的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
  • 2015-09-23
  • 2014-05-29
  • 2014-05-08
  • 2012-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多