2014-07-20 66 views
1

下面RGD htaccess的是我的.htaccess文件上改寫多個查詢

RewriteEngine On 

RewriteRule ^(.*)/(.*)$ /manage/member/index.php?action=$1&id=$2 [L] 
RewriteRule ^(.*)/(.*)/(.*)$ /manage/member/index.php?action=$1&id=$2&sub_action=$3 [L] 
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ /manage/member/index.php?action=$1&id=$2&sub_action=$3&sub_id=$4 [L] 

# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 

DirectoryIndex index.php 

我得到這個$ _GET對我的前幾行

$action = $_GET['action']; 
$id = $_GET['id']; 
$sub_action = $_GET['sub_action']; 

如果我在一個網址發送類似

http://subdomain.mydomain.com/manage/member/edit/5 

它可以得到的動作編輯和ID爲5

但是,如果我發送

http://subdomain.mydomain.com/manage/member/edit/5/permission 

它無法檢索sub_action作爲權限。我應該怎麼做才能使它工作

它檢索5作爲$ 1和許可作爲$ 2和$ 3爲空。

我應該放入什麼.htaccess以允許$ 3和$ 4爲空或有價值但能夠通過$ _GET在獲得價值時進行檢索。

回答

1

讓你的規則是這樣的/manage/.htaccess

DirectoryIndex index.php 
RewriteEngine On 
RewriteBase /manage/ 

# skip rewrite rules for all files and directories  
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

RewriteRule ^([^/]+)/([^/]+)/?$ member/index.php?action=$1&id=$2 [L,QSA] 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ member/index.php?action=$1&id=$2&sub_action=$3 [L,QSA] 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ member/index.php?action=$1&id=$2&sub_action=$3&sub_id=$4 [L,QSA] 


# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 
+1

謝謝你的知識! – user3504335

+0

不客氣,很高興它解決了。 – anubhava

+0

+1,我喜歡你的條件邏輯流程,比我一直在玩的'S'要容易一點。 – zx81