我試圖做一個雙重定向並不能得到正確的邏輯:雙的.htaccess規則
如果頁面存在,忽略所有規則
2.如果頁面不存在,添加.php擴展名(但將其隱藏在URL欄中)
3.如果該頁面不存在並且它不存在且.php擴展名重定向到單個頁面頁面(query.php)並將輸入的內容追加到url欄中作爲一個可變參數(並在URL欄中輸入)。
實施例的文件結構:
的index.php
pricing.php
query.php
實施例試驗:
[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page)
[domain]/pricing -> [domain]/pricing (showing the pricing.php page)
[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse appended)
的.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ query.php?$1 [L]
實際測試:
好
[domain]/pricing.php -> [domain]/pricing (showing the pricing.php page)
[domain]/pricing -> [domain]/pricing (showing the pricing.php page)
壞
[domain]/somethingelse -> [domain]/somethingelse (showing the query.php page with ?somethingelse_php appended)
.htaccess文件上面我已經做的一切我想重定向到query.php它時,它除了當我吐出$ _GET變量顯示「_php」追加。我假設因爲早先的規則...
Rockett's answ呃很好。以下是確保/路由到index.php的額外步驟:放置在其他規則頂部: #重新路由/到index.php RewriteCond%{REQUEST_URI} ^/$ RewriteRule ^(。*)$/index.php [L] – jasondeegan