且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何重定向20%或空格自动+或 - 与htaccess的?

更新时间:2023-02-23 10:41:28

在你的.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