2012-03-07 32 views
1

嗨即時嘗試重寫myweb.com/ivan到一個簡單的網址。使用mod_rewrite意外的行爲

我在根目錄下有此有關的.htaccess:

RewriteEngine On 
    RewriteRule ^/something$ index.php?page=anunciante&anunciante=something [L,NC] 
    RewriteRule (.*)/?restaurantes/(.+)?$ index.php?page=anunciante&anunciante=something [L,NC] 

是的,兩者是相同的。如果我嘗試進入myurl.com/ivan,我得到'未找到',但是如果我嘗試輸入myurl.com/restaurantes/something,我會進入index.php而沒有任何問題。在我的index.php我有這樣的:

print_r($_GET); die(); 

因此,與myurl.com/restaurantes/something我得到:

Array ([page] => anunciante [anunciante] => something) 

(如預期) 但我不知道爲什麼這不是myurl工作.COM /伊萬 我也嘗試修改規則,如:

RewriteRule ^/?ivan$ index... 
    RewriteRule ^ivan$ index... 
    RewriteRule ^/ivan index... 

所有沒有贏得成功。此外,我不知道在哪裏是要求「的favicon.ico」 .. 這裏是mod_rewrite的日誌: 要求myurl.com/something 日誌:http://pastebin.com/283kq3R8

要求myurl.com/restaurantes/something http://pastebin.com/5QcyuAuW

+1

請使用是'ivan'或'something'一致。也適用於你的接受率。第三,在mod_rewrite url-paths從不以'/'開始,所以'/ something'應該只是'something'。 – Gerben 2012-03-07 16:14:50

回答

0

正如@Gerben所發佈的,不要以/爲前綴。 嘗試:

RewriteEngine On 
RewriteRule ^ivan$ index.php?page=anunciante&anunciante=ivan [L,NC] 
RewriteRule (.*)/?restaurantes/(.+)?$ index.php?page=anunciante&anunciante=something [L,NC] 

http://myweb.com/ivan http://myweb.com/restaurantes/something

+0

btw,爲什麼會在請求中出現'favicon.ico'? – Godfather 2012-03-07 21:12:29

+0

即使您沒有在html中引用它,大多數現代瀏覽器也會查找favicon.ico。你可以用一個mod_rewrite 410或者你可以添加一個。 – RumpRanger 2012-03-09 13:23:38