2012-11-26 53 views
0

我對這些apache2重寫的方式感到困惑。Apache2重寫url

我需要製作一個REST接口,當然我會使用真正的URL。我在localhost atm測試。

http://localhost/ssase12/services/users/ 
http://localhost/ssase12/services/users 

應該被髮送到

http://localhost/index.php?rt=index/users 

所以我需要檢測3.文件夾/名稱,並將其重定向到上面的鏈接 - 用戶= $ 1

使感覺? 我試圖做到這一點與用戶文件夾中放置一個.htaccess ...我可以從服務文件夾做到這一點?所以一切寫在

http://localhost/ssase12/services/blah(/) 

將被髮送以及?

感謝

回答

0

你可以把規則無論是在文檔根

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^ssase12/services/(.*?)/?$ /index.php?rt=index/$1 [L] 

或ssase12目錄:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^services/(.*?)/?$ /index.php?rt=index/$1 [L] 

或服務目錄。

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*?)/?$ /index.php?rt=index/$1 [L]