【问题标题】:mod_rewrite: insert index.php if URL contains Xmod_rewrite:如果 URL 包含 X,则插入 index.php
【发布时间】:2014-02-17 16:36:29
【问题描述】:

我正在尝试使用 mod_rewrite 进行更改:

http://example.com/?wpdmact=process&did=m5d4FG3

到:

http://example.com/index.php?wpdmact=process&did=m5d4FG3

我只想插入index.php

这是我尝试过的代码,但它不起作用:

RewriteCond %{QUERY_STRING} wpdmact=process&did=(.*)
RewriteRule (.*) /index.php?wpdmact=process&did=%1 [R=301,L]

我已在同一站点上成功创建了以下类似重定向:

RewriteCond %{QUERY_STRING} page_id=(.*)&preview=true
RewriteRule (.*) /index.php?page_id=%1 [R=301,L]

我有一个 Wordpress 站点,它的根文件夹中有一个静态的 index.html 以及 index.php。这是为了有一个更轻、更快的加载主页。这带来的唯一挑战是我在这里提到的两个。它会中断,因为在这些情况下,站点会重定向到 index.html,而不是 index.php

我没有对 mod_rewrite 做很多工作,因此非常感谢您提供的任何帮助。

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    这应该可行:

    RewriteCond %{QUERY_STRING} wpdmact=process&did= [NC]
    RewriteRule ^$ /index.php [R=301,L]
    

    QUERY_STRING 会自动转移到新 URL。

    【讨论】:

    • 将使用[QSA],即附加查询字符串
    • @AtulGupta:这是许多开发人员的误解,但事实并非如此。 QSA 仅在重写规则中更改查询字符串时才需要。
    • @MarkRummel:不客气,很高兴它成功了。
    猜你喜欢
    • 2023-04-08
    • 2011-01-22
    • 2020-07-07
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2011-09-26
    相关资源
    最近更新 更多