1

We had an issue with encoded URLS on our website which caused URL's like:

ros%C3%A9-wine.php

This has now been replaced in the sitemaps file with the correct:

rose-wine.php

However as these URL's were in the wild we now have duplicate pages on Google along with lots of pages with encoded ë's etc.

Is there a way to redirect any encoded URL's to the homepage using htaccess ?

Thanks,

Rick

Martin
  • 22,212
  • 11
  • 70
  • 132
Rick Evans
  • 125
  • 1
  • 2
  • 10
  • [This answer](http://stackoverflow.com/questions/13818776/remove-characters-from-url-with-htaccess) may well be very useful to you. – Martin Jun 01 '16 at 13:06

2 Answers2

1

You can the following redirect in htaccess:

RewriteEngine on

RewriteCond %{THE_REQUEST} /ros%3C%A9-wine\.php [NC] 
RewriteRule ^ / [R=301,L]

This will permanently redirect the uri /ros%3C%A9-wine.php to / .

If there are multiple similar uris to redirect, you may use this :

RewriteEngine on

RewriteCond %{THE_REQUEST} /.*%3C|%A9.*\sHTTP [NC] 
RewriteRule ^ / [R=301,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • What if the OP has 1million wrong URLs in his sitemap? – Daniel W. Jun 01 '16 at 13:13
  • Still, that redirect won't redirect user to correct address - it will just redirect to main page. I don't think that it was the goal. – Jehy Jun 01 '16 at 13:25
  • Not quite 1 Million URL's but certainly a few thousand :) 301'ing the pages to the homepage is probably the best solution as the URLS without the encoding are indexed by Google. The encoding isn't just e's but also loads of non english characters, is there a way to deal with all of these in one go or is it simply a case of writing hundreds of redirects ? – Rick Evans Jun 01 '16 at 13:48
  • @RickEvans to redirect it one go, you should use php script as decribed in my answer. – Jehy Jun 01 '16 at 14:39
0

Of cause you can! For this example, it can be

Redirect ros%C3%A9-wine.php rose-wine.php

Of cause, you can write it manually or even create .htaccess with a program, but if there are many URLS like this, I suggest writing a simple redirect program which replaces all chars like ë with corresponding latin chars.

<?
  $url=$_SERVER['REQUEST_URI'];
  $url2=str_preplace('%C3%A9','e');//repeat as many times for other chars as you need
  if($url!=$url2)//URL was wrong
  {
    Header('Location: '.$url2)//redirect user to correct URL
    exit();
   }
?>
Jehy
  • 4,729
  • 1
  • 38
  • 55
  • this is a PHP rather than an .htaccess solution and so this solution may require the OP to run all their URLs through a PHP file such as with `mod_rewrite` or similar. I'm not sure OP currently does this and it would be a complex beast to establish – Martin Jun 01 '16 at 13:04
  • @Martin as I already mentioned, OP can manage it with a big .htaccess file but it would be a long, manual and ugly method. – Jehy Jun 01 '16 at 13:24