Forum Moderators: phranque

Message Too Old, No Replies

htaccess - Redirecting with special characters

I need to make a redirect from a URL that might contain an e acute

         

8PDesign

7:21 pm on Nov 26, 2009 (gmt 0)

10+ Year Member



Hi,
I need to make a redirect from a URL that might contain an e acute

These don't work in my htaccess:

redirect 301 "/WebDesignMontr%E9al" "http://www.mydomain.com/fr/design-web-montreal.php"

redirect 301 "/WebDesignMontréal" "http://www.mydomain.com/fr/design-web-montreal.php"

This currently triggers my 404
could anyone guide?
thanks!

TheMadScientist

7:43 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would try both of yours without the ", because I think they are incorrect, and I'm not very knowledgeable about what mod_alias 'gets' or 'doesn't get' passed to is with regard to encoding, but if they still don't work, the first thing I'd be tempted to try is:

RedirectMatch 301 /WebDesignMontr.{1}al http://www.example.com/fr/design-web-montreal.php

Which will match 'any character not the end of a line one time'. It's not exactly ideal, but the only way I know of to 'see' and match the encoding for sure is with THE_REQUEST in mod_rewrite, but you might get a match using the above and it doesn't make your redirect generic to the point where you would be matching incorrect locations.

Added: It appears mod_alias matches a %-decoded path, so your first redirect will not match, but the second may.

[httpd.apache.org...]

BTW: http://www.example.com does not auto-link here and cannot be owned, so it's usually the best example domain to use.

8PDesign

8:12 pm on Nov 26, 2009 (gmt 0)

10+ Year Member



thanks for your reply. :)
This does not work... still a 404

/WebDesignMontréal does not get redirected to
[mydomain.com...]

any more ideas?!
thanks!

TheMadScientist

8:40 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So, the location of the page you are trying to redirect is exactly:

http://www.example.com/WebDesignMontréal

No extension.
Not in a sub-directory.

Are there any sub-directories or pages? EG
http://www.example.com/WebDesignMontréal/Page

If there are no sub-directories / pages, and there is nothing else that would match after the first portion, you could try:

RedirectMatch 301 /WebDesignMontr.* http://www.example.com/fr/design-web-montreal.php

jdMorgan

8:49 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try RedirectMatch:

RedirectMatch 301 ^/WebDesignMontr.+al http://www.example.com/fr/design-web-montreal.php

That should match regardless of whether the "e" with accent ague has already been un-encoded or remains encoded as a three-character "%E9" string.

If that doesn't work, see this recent thread on a more-complex solution using mod_rewrite: [webmasterworld.com...]

Jim

8PDesign

9:04 pm on Nov 26, 2009 (gmt 0)

10+ Year Member



thanks all! This worked perfectly:

RedirectMatch 301 ^/WebDesignMontr.+al http://www.example.com/fr/design-web-montreal.php

thanks again!