mod_rewrite,用于.htaccess中的相对路径

时间:2011-02-18 21:28:51

标签: apache .htaccess mod-rewrite

我希望Apache转换或重定向

example.com/someController/someAction/5

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

我想在.htaccess文件中放入一些mod_rewrite规则,我可以将它放在与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位于“子目录”文件夹中。

1 个答案:

答案 0 :(得分:1)

这条规则应该这样做:

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