.htaccess - 301 Redirect for URL With Spaces -


i have situation want redirect incoming url %20 in url replaced - occurrences.

now link -

301 redirect replace spaces hyphens

which gives solution

options +followsymlinks -multiviews 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] 

which works perfect there 1 small issue solution. redirects request images/docs/pdf or other resources , results in 404

can have redirect sections , not incoming links replace , redirect for

www.test.com/colleges/this%20is%20my%20link/123 www.test.com/colleges/this-is-my-link/123 or www.test.com/schools/this%20is%20my%20link/123 www.test.com/schools/this-is-my-link/123 

and leave other requests intact??

change code this:

rewriterule \.(jpe?g|png|gif|ico|bmp|pdf|docx?|txt|css|js)$ - [l,nc]  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] 

Comments