2013-12-16 73 views
1

我有一些困難,創建一個簡單的htaccess的URL重寫。.htaccess和重寫規則

我想是網址與3個參數:

www.example.com =>的index.php

www.example.com/module/ =>的index.php模塊= $ 1

www.example.com/module/action/ =>的index.php?模塊= $ 1 &行動= $ 16

www.example.com/module/action/1 =>的index.php ?模塊= $ 1 &行動= $ 16 & PARAMS = $ 3

我這樣做,有很多教程,但是當我嘗試用最後一個,它的失敗

RewriteRule ^web/([^/]*)$ index.php?module=$1 [L,QSA] 
RewriteRule ^web/([^/]*)/(.*[^/])$ index.php?module=$1&action=$2 [L,QSA] 
RewriteRule ^web/([^/]*)/(.*[^/])/([0-9]*)$ index.php?module=$1&action=$2&params=$3 [L,QSA] 

有人能幫助我嗎?

感謝

BOUFFE

回答

1

你的第二個表達的.*部分/action/後吞噬了什麼,所以你需要限制它一樣的一個/前面,並使用+代替*

RewriteRule ^web/([^/]+)$ index.php?module=$1 [L,QSA] 
RewriteRule ^web/([^/]+)/([^/]+)/?$ index.php?module=$1&action=$2 [L,QSA] 
RewriteRule ^web/([^/]+)/([^/]+)/([0-9]+)/?$ index.php?module=$1&action=$2&params=$3 [L,QSA] 
+0

謝謝!我想我混合了一個URL重寫與正則表達式。* 我會讀更多的文檔 – Bouffe

+0

我完全像'http://www.example.com/templates/professional_website/news.php?ac=post&id=2&p = 1',那我該如何實現呢?到'https://www.example.com/templates/professional_website/news/post/2/1' –