2010-01-16 37 views
1

第一個問題,在這裏不用什麼...阿帕奇/ mod_rewrite的/週期與模式搞亂

我想一個新的條目添加到我的.htaccess文件(Apache服務器)與翻譯這個網址的希望:

http://platform.localhost/category.all 

到這個網址:

http://platform.localhost/index.php?page=category.all 

我目前使用的重寫規則是這樣的:

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

到目前爲止,這條規則對所有URL都正常工作,我只能假設它是打破它的時期。

我試圖實現的是在將「http://platform.localhost/」傳遞到index.php的「page」變量之後的URL中有任何東西。

我知道我錯過了一些愚蠢的東西,請有人指點一下嗎?

乾杯

回答

2

模式表示拒絕點,但你可以做TIS:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L] 
+0

非常好,謝謝。完美工作。 接受的答案。 – GlenCrawford 2010-01-16 12:43:04

0

爲什麼不一樣的東西:

RewriteRule index.php - [L] 
    RewriteRule (.*) index.php?$1 

,因爲我不知道這可能會失敗請記住,如果在匹配模式時包含querystrings,我不確定如果您要求會得到什麼樣的結果:

http://bla.blub/x?q=1

另請注意,這是爲.htaccess /目錄上下文。