如何删除 %20,:,/,? 还有更多来自带有 .htaccess 的 url?我已经尝试了这篇文章中的代码,但仍然没有替换/重定向到新的 url .htaccess url 重写并删除 %20。
这是我的 .htaccess 代码
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one (remove query string)
RewriteCond %{THE_REQUEST} \s/+content\.php\?judul=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
# convert all space (%20) to hyphen
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [N,NE]
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE]
# rewrite rule to call actual PHP handler
RewriteRule ^([^./]+)\.html$ content.php?judul=$1 [L,QSA,NC]
我的链接
http://localhost/web/content.php?judul=Fate/Apocrypha
http://localhost/web/content.php?judul=Isekai%20wa%20Smartphone%20to%20Tomo%20ni
我想将“%20”和“/”替换为“-”,就像这样。
http://localhost/web/content.php?judul=Fate-Apocrypha/
http://localhost/web/content.php?judul=Isekai-wa-Smartphone-to-Tomo-ni/
您可以在上次重写规则之前添加以下 2 条规则:
# replace %20 and / in QUERY_STRING by hyphen
RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?(?:/|%20)+.*)$"
RewriteRule ^ %{REQUEST_URI}?%1-%2 [N,NE]
RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?)/?$"
RewriteRule ^ %{REQUEST_URI}?%1-%2/ [L,R=302,NE]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句