解决方法:更换空间,20%和+连字符 [英] SOLVED: Replace space, %20 and + with hyphens

查看:193
本文介绍了解决方法:更换空间,20%和+连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   301重定向用空格

现在我每天重定向图像打到包含图像的HTML页面。

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]

由于图像通常包括空格,但是HTML页面始终使用连字符,我需要一个解决方案,同时更换所有的空间,20%和+符号的连字符

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

推荐答案

301重定向用空格

解决了这个问题。

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]

这篇关于解决方法:更换空间,20%和+连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆