Can .htaccess 301 redirects work with encoded characters?

Can .htaccess 301 redirects work with encoded characters? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, redirects, url, internationalization, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have an old site with titles in the URL for SEO, but it has URL encoded characters than transliterated Latin characters. Like %20 instead of space character and many other non-Latin characters. The site is not in English.



I'm moving the site to a new CMS and it transliterates the titles before puttng them into URL bar (which is nice and I'm happy to have).



I'm writing 301 redirects in my .htaccess and they work if all characters of the title are in Latin (the same in both side).



How can I redirect the old encoded URLs to the new transliterated URLS using .htaccess?


Solution :

It should just work fine provided that the URL is enclosed in double-quotations.



For example, if you have:




  • Old URL: http://www.example.com/folder%20name/page%20name.html

  • New URL: http://www.example.com/folder/page



You can write:



Redirect 301 "/folder/page%20name.html" http://www.example.com/folder/page

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect