【问题标题】:redirecting URL with .htaccess not working使用 .htaccess 重定向 URL 不起作用
【发布时间】:2013-10-21 23:45:23
【问题描述】:

尝试使用 .htaccess 进行简单的 URL 重写,但似乎不起作用。

想访问http://www.example.com/shop/index.php?route=information/information&information_id=11

使用网址http://www.example.com/MyGreatClub2013

这是我存储在 www.example.com 根级别的 .htaccess 中的内容

RewriteEngine On
RewriteRule ^/MyGreatClub2013$ /shop/index.php?route=information/information&information_id=11 [NC,L]

我是不是做错了什么蠢事?

【问题讨论】:

  • RewriteRules in 'per-directory' context(就像在.htaccess 中删除了前导斜杠(斜杠位于主机字符串的末尾)。他们也删除了查询字符串,以防您会搞砸的。

标签: regex apache .htaccess mod-rewrite redirect


【解决方案1】:

删除前导斜杠:

RewriteEngine On
RewriteRule ^MyGreatClub2013/?$ /shop/index.php?route=information/information&information_id=11 [NC,L,QSA]

.htaccess 中使用的 mod_rewrite 规则与前导正斜杠不匹配,因为 .htaccess 是每个目录。

【讨论】:

    【解决方案2】:

    这是一个不错的指南:http://www.javascriptkit.com/howto/htaccess.shtml

    希望对你有帮助。

    【讨论】:

    • 一个特定的问题应该有一个特定的答案,而不仅仅是一般的“阅读手册”评论。虽然该指南看起来很有用,但处理 this 问题部分的链接将是 be much better.
    猜你喜欢
    • 2015-09-06
    • 2014-11-25
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2023-03-27
    • 2015-03-07
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多