2013-01-23 131 views
0

我想掩蓋URL http://example.com/index.php?path=controller/functionhttp://example.com/controller/function。不需要存在function重新路由URL參數路徑

我該如何用htaccess文件做到這一點?

以下不起作用。

RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript 
RewriteRule ^$ /index [redirect] 
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z/]*)$ index.php?path=$1/$2 [L] 

目前,如果我在瀏覽器中輸入http://example.com/controller/function,我收到一個404錯誤,但進入http://example.com/index.php?path=controller/function作品。

謝謝!

回答

4

你可以試試這個:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !index\.php [NC] 
RewriteRule ^([^/]+)(.*)?$ index.php?path=$1$2 [L] 

它在內部

http://example.com/var1/var2

映射到:

http://example.com/index.php?path=var1/var2

保持傳入尾隨斜線行爲和var2是可選的。

+0

它的工作!非常感謝你。 –

+0

如果您需要將'http:// example.com/uploads/var1/var2/file.txt'重寫爲'http://example.com/index.php?filepath = var1/var2/file.txt' ? –