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

前端 未结 2 1326
一向
一向 2020-12-10 00:04

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

How can I do this with .htacess ?

2条回答
  •  旧巷少年郎
    2020-12-10 00:41

    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

提交回复
热议问题