我想知道如何讓系統從url中讀取參數,而無需在php或jsp中進行GET。 例如:www.example.com/action/logout/
將與www.example.com?action=logout
相同。沒有GET的URL參數
謝謝。
我想知道如何讓系統從url中讀取參數,而無需在php或jsp中進行GET。 例如:www.example.com/action/logout/
將與www.example.com?action=logout
相同。沒有GET的URL參數
謝謝。
標準和流行的做法是使用.htaccess文件。你應該學習如何使用.htaccess重寫規則。它應該看起來像:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(/.*)?$ $3?$1=$2 [N,QSA]
RewriteRule ^(/[^/]+|[^/]+/|/?)$ /index.php [L,QSA]
這將運行在Apache級別,這可能是你想要的。
在的情況下是要格式化它建議使用重寫規則.htaccess文件中
RewriteEngine ON
RewriteRule ^(.*)action/([a-zA-Z0-9]+).*$ $1?action=$2
這將導致服務器解釋乾淨URLS
www.example.com/action/logout/
爲
www.example.com?action=logout
以及
www.example.com/subdirectory/action/logout/otherstuff
爲
www.example.com/subdirectory/?action=logout
請注意,新增/otherstuff
被省略,但查詢傳遞到子目錄。你將需要定製你使用正則表達式的最終規則
[parse_url](http://php.net/manual/function.parse-url.php) –
從重寫規則開始。 – Brad
您是否試圖在沒有GET的情況下執行此操作,或者您是否暗示您無法使用URL來格式化GET原因? – varubi