Friday, September 22, 2017

how to make redirect in .htaccess for url with specific symbols


The problem was to redirect wrong CodeIgniter url with %C2%A0 symbols to another pahe in .htaccess

For example
http://mysite.com/some-page%C2%A0
to
http://mysite.com/other-page


Redirect   301    /some-page%C2%A0     /other-page   does not work

Here I had found some solution:

RewriteCond   %{THE_REQUEST}   ^[A-Z]+\ /[^%?\ ]*\%
RewriteRule    ^. http://www.example.com/     [R=301,L]

This rule redirects all matches with %.. symbols

So I had tried next:

RewriteCond   %{THE_REQUEST}   some-page[^%?\ ]*\%
RewriteRule   ^.    /other-page [R=301,L]

But after testing, it adds to now url an old url as parameters
As the results I had something like this:

http://mysite.com/index.php/other-page?/some-page/&... etc

So, after some googling I have found this

So I had changed

RewriteRule   ^.   /other-page [R=301,L]
to
RewriteRule   .?   /other-page$1? [R=301,L]


So, to make 301 redirect from broken url with % symbols need to do something like this:

RewriteCond   %{THE_REQUEST}   some-page[^%?\ ]*\%
RewriteRule   .?  /other-page$1? [R=301,L]

No comments:

Post a Comment

Restore xampp database from backup

steps: stop mysql xampp 1 - create some backup folder "data_1"  2 - from your current xampp/mysql/data folder move core folders an...