2009-01-08 19 views
1

我想成立.htaccess改寫:的.htaccess的RewriteCond重寫情況下,2級文件夾=信息

example.com/bla/info/ 

example.com/info/index.php?q=bla 

example.com/bla/info/txt/ 

example.com/info/index.php?q=bla&t=txt 

我想瀏覽器仍顯示:

example.com/bla/info/txt/ 

我不想改寫2級重寫,如:

example.com/bla/xxx/ 

example.com/ccc/zzz/aaa/ 

example.com/silly/info/ 

將工作以及

example.com/strange/info/mytxt/ 

這有意義嗎?

任何幫助?

回答

0

如果您以^開始您的模式並以$結尾,則該規則僅適用於整個字符串匹配的情況。

RewriteRule ^/bla/info/$  /info/index.php?q=bla 
RewriteRule ^/bla/info/txt/$ /info/index.php?q=bla&t=txt 

如果您使用不使用[R]選項,則瀏覽器中顯示的URL將是用戶輸入的任何內容。

您是否試圖使這個通用?如果是這樣,你可以使用正則表達式匹配和變量替換。爲了讓「喇嘛」匹配任何字符串到下一個斜槓(/),在你的模式中使用

([^/]+) 

,並在你的替代以$ 1引用它。

RewriteRule ^/([^/]+)/info/$   /info/index.php?q=$1 
RewriteRule ^/([^/]+)/info/([^/]+)/$ /info/index.php?q=$1&t=$2 

我推薦Apache web pages about mod_rewrite瞭解更多信息。

[編輯。固定的規則不包括在模式中的主機名,因爲原來的海報想出]

-
BMB

0

你讓我在正確的軌道上。

我結束了這樣的事情:

RewriteRule ^([^/\.]+)/info/?$ example/info/index.php?q=$1 [L] 

非常感謝

+0

哎呀,我忘了主機名沒有出現在格局。我確定了答案。 – bmb 2009-01-10 22:29:02