如何使用 htaccess 将 %20 或空白自动重定向到 + 或 -? [英] How to redirect %20 or White space automatically to + or - with htaccess?
本文介绍了如何使用 htaccess 将 %20 或空白自动重定向到 + 或 -?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要自动将很多 url 像/file%20name/ore/file name/重定向到/file+name/或/file-name/.
I need to redirect automatically lots of url like /file%20name/ ore /file name/ to /file+name/ or /file-name/.
如何使用 .htacess 执行此操作?
How can I do this with .htacess ?
推荐答案
在你的 .htaccess 中试试这个规则:
Try this rule in your .htaccess:
RewriteEngine on
Options +FollowSymlinks
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^(\S*)\s+(\S* .*)$" $1+$2 [N,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*)\s(\S*)$" /$1+$2 [L,R=302,NE]
R=301 将重定向为 https 状态 301
R=301 will redirect with https status 301
L 将制定最后的规则
NE 用于无编码 URI
NE is for no encoding URI
这篇关于如何使用 htaccess 将 %20 或空白自动重定向到 + 或 -?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文