簡體   English   中英

想使用 htaccess 從 url 中刪除參數

[英]want to remove paramters from url using htaccess

想使用 htaccess 從 url 中刪除參數 我的 url 看起來像這樣

http://localhost/details?id=179&title=abcdefghij

我想像這樣轉換它(或任何更好的建議)

http://localhost/details/179/abcdefghij

請幫助我如何實現它

要將/details?id=123&title=foobar/details/123/foobar您可以在root.htaccess使用以下規則:

RewriteEngine on
#1  redirect "/details?id=123&title=foobar" to "/details/123/foobar"
RewriteCond %{THE_REQUEST} /details/?\?id=([^&]+)&title=([^\s]+) [NC]
RewriteRule ^ /details/%1/%2? [L,R]
#2 internally rewrite the requested url "/details/123/foobar" to "/details?id=123&title=foobar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/([^/]+)/([^/]+)/?$ /details?id=$1&title=$2 [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM