【问题标题】:mod_rewrite that operates on relative paths in .htaccess在 .htaccess 中的相对路径上运行的 mod_rewrite
【发布时间】:2011-02-19 05:39:10
【问题描述】:

我希望 Apache 转换或重定向

example.com/someController/someAction/5

example.com/?c=someController&a=someAction&id=123

我想将一些 mod_rewrite 规则放在一个 .htaccess 文件中,我可以将它放在与 index.php 相同的目录中。在上面的示例中,.htaccess 和 index.php 位于 example.com 文件夹中。

我希望规则在相对路径上运行,这样如果我的站点位于另一个域和子目录中,它就可以工作。示例:

otherdomain.com/subdirectory/someController/someAction/5

otherdomain.com/subdirectory/?c=someController&a=someAction&id=123

在本例中,index.php 和 .htaccess 位于“子目录”文件夹中。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    这条规则应该这样做:

    RewriteRule ^(.*/)?([^/]+)/([^/]+)/([^/]+)$ $1?c=$2&a=$3&id=$4
    

    【讨论】:

    • .htaccess 的完整内容是什么?
    • @arex1337:您只需要添加强制性的RewriteEngine on
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 2011-08-15
    • 2012-02-24
    • 2018-12-23
    • 2016-03-26
    相关资源
    最近更新 更多