我使用.htaccess獲得更好的URL。使用.htaccess重寫問題
我有這個PHP頁面:
治療,line.php
隨着
#rewrite treatments-line
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
我能順利進入頁面/處理/線/ the_id_of_the_page。
但是當我創建一個頁面處理.php時,重寫處理行不起作用,它只是顯示首頁。
對於測試時,我改變方法改寫成這樣:
#rewrite treatments-line
RewriteRule ^/?treatment/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
我剛剛更名爲治療(「S」),上/治療/線路重寫/ the_id_of_the_page工作正常,但我不想更改名稱。
所以,我可以看到與名稱有衝突,因爲treatments.php文件。
我該如何解決這個問題?
這兩個PHP頁面位於網站的根目錄中。
EDIT2:
這是我整個的.htaccess代碼:
Options -MultiViews
RewriteEngine on
#remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_URL} /(.*)$
RewriteRule ^(.*)$ %1.php [NC,L]
#redirect posts-view
RewriteRule ^/?post/([0-9]+)$ posts-view.php?id=$1 [NC,L]
#rewrite products-zone
RewriteRule ^/?products/zone/([0-9]+)$ products-zone.php?id=$1 [NC,L]
#rewrite products-category
RewriteRule ^/?products/category/([0-9]+)$ products-category.php?id=$1 [NC,L]
#rewrite products-solution
RewriteRule ^/?products/solution/([0-9]+)$ products-solution.php?id=$1 [NC,L]
#rewrite products-line
RewriteRule ^/?products/line/([0-9]+)$ products-line.php?id=$1 [NC,L]
#rewrite treatments-line
RewriteRule ^/?treatments/line/([0-9]+)$ treatments-line.php?id=$1 [NC,L]
#rewrite treatments-category
RewriteRule ^/?treatments/category/([0-9]+)$ treatments-category.php?id=$1 [NC,L]
#rewrite product-view
RewriteRule ^/?products/([0-9]+)$ product-view.php?id=$1 [NC,L]
#redirect lang
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/(.*)$ $2.php?lang=$1 [L]
#RewriteRule ^([^\.]+)/?$ index.php?lang=$1 [L]
你叫兩個文件'治療,line.php'和'treatments.php'和你想有兩個相同的重寫URL模式? – Perumal
不,這兩個頁面有不同的內容。我只想重寫URL模式治療line.php。 – user2519032
是的。這是因爲有'treatments.php'。 – Perumal