2011-04-14 99 views
0

我的代碼庫位於url.com/與/公共住房的index.php和的.htaccess,該服務器配置爲以點url.com的.htaccess URL路由

我的.htaccess看起來是這樣的:

RewriteEngine on 
ServerSignature On 
Options +Indexes +FollowSymlinks +MultiViews 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php 

RewriteRule ^([-A-Za-z0-9]+)/([-A-Za-z0-9]+).([-A-Za-z0-9]+)$ index.php?module=$1&action=$2&return=$3 
RewriteRule ^([-A-Za-z0-9]+).([-A-Za-z0-9]+)$ index.php?module=$1&action=index&return=$3 

我想是以下網址獲得如下:

url.com/users/list.json equal = module = users, action = list, return = json

url.com/users/list.json?from=0 & to = 15 equal = module = users, action = list, return = json, from = 0, to = 15

這可能嗎?我一直盯着牆壁撞了很長時間,試圖獲得這項工作,所以我正在爲此付出代價

回答

3

你可以嘗試:

RewriteRule ([-A-Za-z0-9]+)/([-A-Za-z0-9]+)\.(json|xml)$ /testrewrite.php?module=$1&return=$3&action=$2 [L,QSA] 

的QSA選項將保留查詢字符串的機智。

0

RewriteRule模式根本不匹配請求的URL路徑作爲第三條路徑的模式段[0-9]+不匹配List

+0

有斑點。 我在做:RewriteRule ^([--A-Za-z0-9] +)/([--A-Za-z0-9] +)$ index.php?module = $ 1&action = $ 2 但當我print_r($ _ GET)它的空,任何想法,爲什麼這可能是? – azz0r 2011-04-14 21:46:52

+0

@ azz0r:是否有一個名爲「User」,「User/List」或類似的文件?我這種情況下,這種行爲可能是由* MultiViews *造成的。 – Gumbo 2011-04-14 21:51:16

+0

通過/public/index.php它使用get _GET ['module']和相應的動作來加載正確的文件和輸出。 – azz0r 2011-04-14 21:54:48

0

Apache的%{QUERY_STRING}將在您的規則中維護GET變量。例如:

RewriteRule ^([-A-Za-z0-9]+)/([-A-Za-z0-9]+).([-A-Za-z0-9]+)$ index.php?module=$1&action=$2&return=$3?%{QUERY_STRING}