如何重定向20%或空格自动+或 - 与htaccess的? [英] How to redirect %20 or White space automatically to + or - with htaccess?
问题描述
我需要自动重定向URL很多像/文件%20name /矿石/文件名/到/文件名+ /或/文件名/.
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
RewriteRule ^(.*)(\s|%20)(.*)$ /$1-$3 [R=301,L,NE]
R = 301将与重定向HTTPS状态301
R=301 will redirect with https status 301
L时可以使最后一个规则
L will make last rule
NE是无法逃避查询字符串
NE is for no escaping query string
QSA将追加现有的查询参数
QSA will append your existing query parameters
$ 1和$ 3为你REQUEST_URI的组件之前和空格字符后出现的
$1 and $3 are components of your REQUEST_URI appearing before and after space character
如果你想 +
的目标规则,而不是 -
请更改为 / $ 1 + $ 3
If you want +
in the target rule instead of -
please change that to /$1+$3
这篇关于如何重定向20%或空格自动+或 - 与htaccess的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!