2

I want to use redirect 301 rules (i.e. I hope to be able to avoid rewriting rules) to redirect URLs that contain special characters (like é, à ,...) like for instance

redirect 301 /éxàmple http://mydomain.com/example

However, simply adding this doesn't work. Any suggestions?

jevon
  • 3,197
  • 3
  • 32
  • 40
Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
  • Have you tried URL encoding, or escaping the characters in any other way (e.g. \x0NNN)? Have you saved your file with the correct encoding (UTF-8, ISO-xxxx, ...)? – jevon Jan 25 '12 at 12:53
  • I do have tried with URL encoding, i.e. using %E1 instead of the á and so on. I have also saved the file using UTF-8 but the redirection rule does not trigger – Jordi Cabot Jan 25 '12 at 13:11
  • Following your advice (and starting from an old backup copy of .htaccess to avoid encoding conflicts) I managed to make all rules with accents to work except for rules that include the à character. Difficult to understand why characters like é work and not à. Ideas? – Jordi Cabot Jan 25 '12 at 20:12

2 Answers2

2

How to troubleshoot this on a Windows system

On Windows, you can use Notepad++ to enter Unicode characters correctly. After launching Notepad++, select 'Encoding in UTF-8 without BOM' from the 'Encoding' menu, then type your Unicode characters and save the file.

To make sure that the characters have been saved properly, download a hex editor for Windows and make sure that é is saved as c3 89 and à is saved as c3 a0.

Previous response where I assumed that you are on a Linux system

Most likely the Unicode characters have not been saved properly in .htaccess file.

What do you get when you try this command:

grep -o .x.mple .htaccess | od -t x1 -c

You should get this if your Unicode characters are saved correctly.

0000000  c3  a9  78  c3  a0  6d  70  6c  65  0a  65  78  61  6d  70  6c
        303 251   x 303 240   m   p   l   e  \n   e   x   a   m   p   l
0000020  65  0a
          e  \n
0000022

If you have xxd or hd installed, you can get a neater output to do your troubleshooting:

$ grep -o .x.mple .htaccess | xxd -g1
0000000: c3 a9 78 c3 a0 6d 70 6c 65 0a 65 78 61 6d 70 6c  ..x..mple.exampl
0000010: 65 0a                                            e.

In all the outputs you can see that é is saved as the binary numbers: c3 89. You can see from http://www.fileformat.info/info/unicode/char/e9/index.htm that the é when encoded in UTF-8 is indeed two-bytes: 0xC3 and 0xA9.

Similarly, à in UTF-8 format is: 0xC3 0xA0. See http://www.fileformat.info/info/unicode/char/e0/index.htm. You can see these codes in the output as well.

Susam Pal
  • 32,765
  • 12
  • 81
  • 103
  • I´m using Apache under windows. I´ve changed the encoding of the file to Unicode but now I get an internal sever error – Jordi Cabot Jan 25 '12 at 12:37
  • How did you change the encoding of the file to Unicode? Which Unicode format did you choose while encoding the file? Was it UTF-8? – Susam Pal Jan 25 '12 at 12:39
  • Yes it is now utf-8. I´ve changed the encoding using notepad++ and now I don´t get the error but the redirection rule doesn´t get yet triggered – Jordi Cabot Jan 25 '12 at 13:12
  • 1
    I could reproduce the situation on my Windows XP laptop and it works great for me. I would suggest that you create your .htaccess from scratch using Notepad++ with your encoding set to 'UTF-8 without BOM'. This is just to make sure that you are starting afresh and you are not working with any mistakes made in the past. – Susam Pal Jan 25 '12 at 13:18
  • For troubleshooting purpose, make sure that for the appropriate `Directory` entry in httpd.conf, you have `AllowOverride All`. You should be able to find this directive by searching for '.htaccess' in httpd.conf. Also, make sure that you have `LoadModule alias_module modules/mod_alias.so` present in httpd.conf. – Susam Pal Jan 25 '12 at 13:31
  • Really weird. I´ve checked the module is there and also the AllowOverride but keeps failing. At least it´s good to know that it "should" work. I´ll keep trying to see if I can figure out what´s going on – Jordi Cabot Jan 25 '12 at 16:02
  • Another thing you could check is whether you are creating the .htaccess at the right place. If your Apache configuration is the default one, you should have the .htaccess file in 'htdocs' directory for troubleshooting purpose. The directory where you put the 'htdocs' file should be also mentioned in a 'DocumentRoot' directive in httpd.conf file. – Susam Pal Jan 25 '12 at 16:07
0

These should work, but it depends on some things that you have to check as a checklit:

  • Do you have mod_alias enabled? If not, you should run a2enmod mod_alias
  • Do you have some redirection to your example page? (Redirections are applied before aliases)

Then, instead of converting it to UTF-8, you can try to put the characters as they're encoded by browsers, for example %C3%A9 for é, etc.

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87