2012-08-24 64 views
1

我使用的使用URL如下前端控制器:使用正則表達式來替換斜線點在URL

http://www.domain.com/index.php?action=main.Main, 其中「主要」是模塊和「主」是動作。

對於URL重寫我的htaccess的使用這行:

RewriteRule ^([^/]+)\.html$ index.php?action=$1 [QSA] 

這導致http://www.domain.com/main.Main.html

現在,我該如何更換模塊和行動之間的點以斜線,這樣的結果看起來像這樣: http://www.domain.com/main/Main

回答

2

試試這個,然後:

RewriteRule ^(.*)/(.*)$ index.php?action=$1.$2 [QSA] 
+0

現貨,謝謝。 –

0
RewriteRule ^(.*)/(.*)$ index.php?module=$1&action=$2 [QSA] 
+0

你提出什麼我將模塊和動作分離成單獨的變量,那麼你的答案就有意義了。但在我的情況下,我只有一個變量$ 1,它是'module.action',我想用斜線替換該點。 –

1

試試這個:

RewriteCond %{REQUEST_URI} \.html$ 
RewriteRule ^(.*)/(.*)\.html$ /$1.$2.html [L] 

RewriteCond %{REQUEST_URI} \.html$ 
RewriteCond %{REQUEST_URI} !/.+/ 
RewriteRule ^([^/]+)\.html$ index.php?action=$1 [L,QSA] 

這將需要像一個請求:http://www.domain.com/main/something/action/Main.html和重寫的URI:/index.php?action=main.something.action.Main