【问题标题】:htaccess redirects are "ignored"htaccess 重定向被“忽略”
【发布时间】:2013-02-19 00:02:44
【问题描述】:

已查看有关此的所有其他帖子,但似乎无法使其正常工作。我无法更改 Joomla 配置、项目等的原因有很多,但无论如何,无论如何,这些似乎都应该起作用。

简而言之,我希望 any 链接带有 Itemid=30 以重定向到给定的链接。我究竟做错了什么?前 3 行是我尝试过的,最后一行是有效的。

RedirectMatch 301 ^Itemid=30$ http://inside.beta.oursite.com/index.php?option=com_cware&view=courses&Itemid=125

redirect 301 index.php?option=com_cware&view=courses&Itemid=30 http://inside.beta.oursite.com/index.php?option=com_cware&view=courses&Itemid=125

RewriteEngine On
RewriteCond %{QUERY_STRING} Itemid=30
RewriteRule ^Itemid=30/$ index.php?option=com_content&view=article&id=106&Itemid=121 [R=301]


# If query string contains "username=admin"
RewriteCond %{QUERY_STRING} username=admin
# Block it without mercy
RewriteRule .* - [F]

【问题讨论】:

标签: .htaccess


【解决方案1】:

Redirect 只考虑 URL 路径,不包括查询字符串。如果要考虑查询字符串,则必须使用mod_rewrite

同样适用于RewriteRule

如果您希望匹配主机名、端口或查询字符串,请分别使用带有 %{HTTP_HOST}、%{SERVER_PORT} 或 %{QUERY_STRING} 变量的 RewriteCond。

因此,如果您想匹配某个查询字符串并将所有 URL 重定向到某个其他 URL,请结合使用 RewriteCond 和 RewriteRule

RewriteEngine On
RewriteCond %{QUERY_STRING} Itemid=30
RewriteRule .* index.php?option=com_content&view=article&id=106&Itemid=121 [R=301]

这会将任何带有包含Itemid=30 的查询字符串的URL .* 重定向到index.php?option=com_content&...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多