1

我有以下重写规则

<filesMatch  "^(member)$">
    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule ^/(.*)/(.*)/(.*)$  /member-profile.php?ID=$2 [L]
</filesMatch>

<filesMatch  "^(community-events)$">
    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule ^/(.*)/(.*)/(.*)/(.*)$  /community-events.php?ID=$3 [L]
</filesMatch>

也就是说,显然重写了这个

mydomain.com/comunity-events/category/id/name 

对此

mydomain.com/comunity-events.php?myvariables

现在,我想要一个没有起始“文件夹”的新重定向,就像这样

mydomain.com/business-category/business-name

mydomain.com/business-profile.php?variables

考虑到当前的配置,这是否可能,而无需为每个类别名称进行重定向?

4

1 回答 1

0

您甚至不需要filesMatch指令,因为您可以匹配起始部分RewriteRule本身。

您可以将 .htaccess 替换为以下规则:

Options +FollowSymlinks -MultiViews
RewriteEngine On

# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID=$2 [L,QSA,NC]

# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID=$3 [L,QSA,NC]

# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name=$2 [L,QSA]
于 2016-10-04T15:14:39.967 回答