2016-10-04 28 views
1

我有如下因素重寫規則重寫友好的URL,型動物圖案

<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 

是,即使有可能,鑑於目前的配置,而不進行重定向爲每個類別的名字嗎?

回答

1

你甚至不需要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] 
+1

偉大的作品! :) 謝謝! – valiD