【问题标题】:mod_rewrite rule for redirecting url用于重定向 url 的 mod_rewrite 规则
【发布时间】:2013-09-05 22:43:01
【问题描述】:

我正在尝试找出从以下 URL 重定向的 mod_rewrite 规则:

/archives/collections/archon/index.php?p=collections/controlcard&id=450

到这里:

/archives/collections/archon/index.php?p=collections/findingaid&id=450

id 参数不会是静态的。

感谢您的帮助。

.htaccess 的当前内容:

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{QUERY_STRING} ^p=collections/controlcard&id=([0-9]+)$
RewriteRule ^index.php$ index.php?p=collections/controlcard&id=%1 [R=301,L]

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    使用%{QUERY_STRING} 你可以这样做:

    Options +FollowSymLinks -MultiViews
    
    RewriteEngine On
    RewriteBase /archives/collections/archon/
    
    RewriteCond %{QUERY_STRING} ^p=collections/controlcard&id=([0-9]+)$
    RewriteRule ^index.php$ index.php?p=collections/findingaid&id=%1 [R=301,NC,L]
    

    【讨论】:

    • @codeman 不像在中那样工作?你的htaccess还有其他规则吗?根文件夹中有多个 .htaccess 文件还是只有 1 个?
    • 只要它不重定向到任何东西,它就不起作用。 .htaccess 中没有其他规则。这个 .htaccess 不在根目录下,它在 archon 目录下,会不会是问题所在?
    • 是的,这可能是问题,因为规则会有所不同,请查看更新并让我知道它是否有效
    • 您提供的更新现在重定向,但它实际上附加了本地系统 htdocs 路径,例如:/data/htdocs/archives/collections/....
    • @codeman 发布您的 htaccess,以便我查看可能是什么问题。可能是某些规则发生冲突或缺少某些内容,例如 RewriteBase。
    【解决方案2】:

    在您的 archon/.htaccess 文件中尝试此代码:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /archon/
    
    RewriteCond %{QUERY_STRING} ^p=collections/controlcard(&.*|)$ [NC]
    RewriteRule ^(index\.php|)$ $1?p=collections/findingaid%1 [R=301,L,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-03
      • 2011-09-08
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      相关资源
      最近更新 更多