不止一个htaccess重写规则

时间:2016-02-05 13:10:24

标签: .htaccess url-rewriting

我在理解方面遇到了一些麻烦.htaccess基本上我试图有一个以上的重写规则;例如,我有一个个人资料页面,然后我也想重写索引页面,所以如何做到这一点;在我之前的尝试中,我只能使用一个重写规则,也许我做错了;我有一个包含链接$this->Paginator->sort('delivery_date','Delivery Date'); 和索引页/profile/profile.php?user=$username的个人资料页面,如何让个人资料页面看起来像account.php?page=featured,帐户页面看起来像/account/$username那么我将如何在线下添加更多?

account.php文件位于根目录中。

/account/featured

这是我当前的.htaccess,当我尝试复制并粘贴它然后在它下面使用它时,它使用了主题标签并显示它们RewriteEngine On RewriteBase / RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2 Options All -Indexes ErrorDocument 403 Denied 它不起作用。

1 个答案:

答案 0 :(得分:2)

正如我的评论中所提到的,Apache无法分辨哪个文件要重写。因此,您需要更改其中一个URI结构。作为建议,请更改配置文件。

以下示例说明如何执行此操作:

RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2 [L]
RewriteRule ^account/([^/]+) /account.php?page=$1 [L]
RewriteRule ^profile/([^/]+) /profile/profile.php?user=$1 [L]

记住[L]标志,这会导致重写在找到匹配时停止。

相关问题