Replace space, and + with hyphens [duplicate]

2020-03-26 08:30发布

Possible Duplicate:
301 Redirect With Spaces

Right now I'm redirecting every Image hit to the html page which contains the image.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} (bing.com|google|yahoo|stumbleupon.com|reddit.com|pinterest.com) [NC]
RewriteRule (.*)\.(gif|jpg|png)$ /$1.html [R,L]

Since the Images often include spaces but the html pages always use hyphens, I need a solution to also replace all spaces, %20 and + symbols with hyphens

1条回答
SAY GOODBYE
2楼-- · 2020-03-26 09:20

301 Redirect to replace all spaces to hyphens

Solves the problem

RewriteEngine On
RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
查看更多
登录 后发表回答