且构网

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

htaccess的干净的网址和放大器;代替空格和%20 -

更新时间:2023-02-23 10:36:25

我有罪书面code超过2年前的:P

I am guilty of writing that code more than 2 years back :P

这可以通过这个code被无限简化为:

That can be hugely simplified by this code:

# remove spaces from start or after /
RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L]

# remove spaces from end or before /
RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L]

# replace spaces by - in between
RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]

PS:必须补充一点,你需要修复这些URL还的来源,因为它实在是不正常的情况下获得的URL像这样

PS: Must add that you need to fix the source of these URLs also because it is really not normal to be getting URLs like this.