2012-04-10 77 views
0
RewriteEngine On 

RewriteRule ^/showlisting/(.*)$ showlisting.php/$1 [L] 
RewriteRule ^/listings/(.*)$ listings.php/$1 [L] 

RewriteCond %{HTTP_HOST} ^mydomain\. 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L] 

ErrorDocument 404 /notfound 

在上面的工作,這就是我想要達到的目標:條件刪除.PHP並不如預期

  1. 我要轉發的任何URL如www.mydomain.com/ showlisting/my-listing-data/with-more-slashes/and-some-text來顯示www.mydomain.com/showlisting*內容.php */my-listing-data/with-more-slashes /和一些文本,但URL掩碼,以便.php不會出現在瀏覽器窗口。
  2. 我也想追加www當www不存在於搜索引擎優化目的的請求,雖然我不知道這是多麼重要這些天。

當我訪問www.mydomain.com/showlisting/my-listing-data/with-more-slashes/and-some-text但是它顯示了一個404錯誤,但要以.php加入showlisting,它工作正常。有任何想法嗎?

但是請注意www的附加。工作正常 - 這不是我正在努力的部分,儘管我將這部分代碼包括在內以進行全面分析。

+1

在哪個目錄中的.htaccess文件在什麼位置? – Dion 2012-04-10 19:51:37

+0

確保斜槓同步。它可以是規則正則表達式的w/o,也可以是替換規則。 – hakre 2012-04-10 19:53:01

+0

一切都在public_html文件夾下。所有.php文件,.htaccess等 – jeffkee 2012-04-10 19:57:20

回答

1

也許

RewriteEngine On 

RewriteRule ^showlisting/(.*)$ showlisting.php/$1 [L] 
RewriteRule ^listings/(.*)$ listings.php/$1 [L] 

RewriteCond %{HTTP_HOST} ^mydomain\. 
RewriteRule ^$ http://www.mydomain.com/ [R=301,L] 

ErrorDocument 404 /notfound 
+0

沒有運氣 - 根據你的規格改變它。我應該指定www。附加作品很好。這是.php問題,目前不起作用。 – jeffkee 2012-04-10 19:59:18

+0

也許刪除第一個斜槓? (見上面更新的代碼) – Dion 2012-04-10 20:02:02

+0

Yup工作。謝謝! – jeffkee 2012-04-11 01:21:35