开发者

How to redirect %20 or White space automatically to + or - with htaccess?

I need to redirect automatically lots of url like /file%20name/ ore /file name/ to /file+name/ or /file-name/.

How can I d开发者_开发百科o this with .htacess ?


Try this rule in your .htaccess:

RewriteEngine on
Options +FollowSymlinks

# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^(\S*)\s+(\S* .*)$" $1+$2 [N,NE]

# executes when there is exactly 1 space in URI
RewriteRule "^(\S*)\s(\S*)$" /$1+$2 [L,R=302,NE]
  • R=301 will redirect with https status 301

  • L will make last rule

  • NE is for no encoding URI


You can use something like this:

RewriteRule file\ name\ http://example.com/file+name [R=301,NC,NE,L]

Edit after comment:

Try this:

RewriteRule ^([^\ ]*)\ (.*)$ $1-$2 [E=rspace:yes,N]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜