我正在嘗試將&我的 URL 中的所有內容轉換為&:
這是我的網址:https://test.com/index.php?option=com_media&task=file.upload&tmpl=component&820470bdbcec556c83a51cb33ca92922=kfp1tif94iuetenuab6hfi5mvd&690012fb504cea7eee8475c0963a8fc4=1&asset=image&format=json
這是我試圖實作的目標:
https://test.com/index.php?option=com_media&task=file.upload&tmpl=component&820470bdbcec556c83a51cb33ca92922=kfp1tif94iuetenuab6hfi5mvd&690012fb504cea7eee8475c0963a8fc4=1&asset=image&format=json
到目前為止,我已經嘗試了以下規則:
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)(&)(.*)
RewriteRule ^.*$ %{REQUEST_URI}?%1&%3 [N,L,R=301]
但它只是替換最后一個&
非常感謝你的幫助
uj5u.com熱心網友回復:
您可以使用這 2 條規則將 all 替換&為&. 請注意,最后只會有一個重定向:
RewriteEngine On
# recursively replace & with &
RewriteCond %{QUERY_STRING} (.*)&(.*) [NC]
RewriteRule ^ %{REQUEST_URI}?%1&%2 [N,DPI,E=done:1]
# redirect in the end
RewriteCond %{ENV:done} =1
RewriteCond %{QUERY_STRING} !& [NC]
RewriteRule ^ %{REQUEST_URI} [R=301,NE,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/446688.html
標籤:正则表达式 阿帕奇 .htaccess 改写 url重写
