2011-06-13 69 views
1

我在.htaccess:關於產品的.htaccess

RewriteRule ^index.php cont.php?id=1 

,但如果我衝浪到的index.php圖像= bla.jpg

由於某種原因,我看到頁面:續.PHP?ID = 1

我如何能做的唯一URL 的index.php將打開cont.php?ID = 1,而不是別人LIK e index.php?image = bla.jpg

謝謝。

回答

2

您需要檢查請求的URI查詢,以及:

RewriteCond %{QUERY_STRING} ^$ 
RewriteRule ^index\.php$ cont.php?id=1 
0
RewriteRule ^index.php cont.php?id=1 [QSA] 

您neew QSA屬性 - 它告訴Apache的index.php

+0

不工作.... – John 2011-06-13 09:00:37

1
RewriteRule ^index.php$ cont.php?id=1 

附加多萊爾標誌與index.php(這就是^的含義)。您需要說的是,路徑必須在結尾也是如此,這由$標誌指示。 (Apache docs

RewriteRule ^index\.php$ cont.php?id=1 

擺脫.也advisible,否則任何單個字符(例如index1php)。

+0

沒有工作.... – John 2011-06-13 09:00:20

+0

兩個重要的事情提 1)逃避「」字符2)在RewriteRule之前使用RewriteCond屬性3)[QSA]不起作用,因爲它意味着只在最後附加查詢字符串。對於你的情況,QSA是不適合的。去與這個答案[鏈接](http://stackoverflow.com/questions/6328316/question-about-htaccess/6328357#6328357) – acpmasquerade 2011-06-13 10:43:04

2
RewriteRule ^index.php cont.php?id=1 

匹配一切開始後的任何查詢字符串傳遞給rewrited地址