301 redirect special charecter issue - apache

The URLs with special characters such as é, ü do not redirect correctly.
For example : Redirect 301 /de/pages/schuhe_mit_schmaler_füßbreite http://www.mydomain.com/de/schuhe-für-schmale-füße/l/
I already tried using the suggestions in this stack post, but it does not work for me.
working rule :
Redirect 301 /de/pages/duo_latest http://www.mydomain.com/de/entdecken-sie-duo/neues/
not working rule :
Redirect 301 /fr/pages/duo_latest http://www.mydomain.com/fr/découvrez-duo/nouvelles/
not working rule contain special character é

Make sure that the text editor you are using to save to your .htaccess file supports UTF-8 encoding. If you are using Notepad, configure the settings so that it is not saving as ANSI.
If you cannot get it to save to UTF-8, create a completely new .htaccess file that is saved in UTF-8 and replace the old file with the new one.

This works probably fine
RewriteRule ^türen/(.*) http://google.de?$1 [L]
What is your problem? Can you post some more details

Related

htaccess redirection implied html extension not working

I've tried many things before coming here, it should be a simple problem, but there is something I miss for sure.
I want to redirect a bunch of URLs to another ones, one by one, and here is an example in my .htaccess file :
RewriteEngine On
Redirect 301 /index.php/Microcontrôleurs_Généralités https://newdomain.org/Microcontrôleurs_Généralités
The thing is that the old URLs are files in a real folder "index.php" but with ".html" extension.
When I go to https://olddomain.org/Microcontrôleurs_Généralités, apache serves me the implied .html file. I can go to https://olddomain.org/Microcontrôleurs_Généralités.html too, it's the same file on disk.
But my redirection as above does not redirect anything.
If I add the .html extension to the file like this :
RewriteEngine On
Redirect 301 /index.php/Microcontrôleurs_Généralités.html https://newdomain.org/Microcontrôleurs_Généralités
Then, if I go to the URL with explicit ".html" at end, it is redirected correctly, but if I miss the .html, apache says the URL was not found.
I've turned this in my head numerous times, I can't figure out the real problem.
Help would be much apreciated, thx.

Redirect strange URLs with two periods in them

I had a static HTML website that I recently converted over to drupal. I have been monitoring my sites 404 errors in webmaster tools and drupal reports and have noticed that google has indexed strange urls. My guess is they came from relative links that were created improperly from the older static HTML site.
Here is an example:
www.example.com/items../item-page.html
The actual page is:
www.example.com/items/item-page.html
The new drupal site doesn't even have .html extensions. I am using URL redirect and path auto modules and have redirects setup for all of the old urls to make sure they are 301'd to the new URL structure (e.g. www.example.com/items/item-page.html would be 301 to www.example.com/items/item-page).
I have access to the server so I am doing my redirects in the apache httpd.conf file instead of .htaccess. I tried the following code to redirect ../ to / but I am not having any luck:
RewriteRule ^\.\./(.*) /$1 [R=301,NC,L]
This rule doesn't do anything when I go to a url with the ../ in it. Is there a rewriterule that can match ../ and remove it from any url?
NOTE: I have other redirects in apache httpd.conf that are working fine...such as:
RewriteRule ^items/pdf/(.*)$ /sites/default/files/documents/items/$1 [R=301,NC,L]
So I don't think its my server configuration.
EDIT:
I noticed that the rewrite rule above for rewriting the pdf directory works even with the .. in the URL. Example:
http://www.example.com/items../pdf/somedocument.pdf
redirects to
http://www.example.com/sites/default/files/documents/items/somedocument.pdf
So it looks like the .. is completely ignored in rewrite rules, which is why I can't get anything to work. Does anyone know a way around that?
I believe you need to escape your forward slash.
I believe rewriterule acts against the HTTP request URI, not the page link.
Consequently, I believe you will need to remove the carat to find a match, and analyze your intentional URLs to see if that would have a negative impact elsewhere.
You can use this
RewriteRule ^/items\.\.(.+)$ /items/$1 [L,R]
This will redirect /items..foobar to /items/foobar
I was not able to fix the issue using rewrite rules in apache due to the rewrite rules not finding ".." in the url for unknown reasons.
My solution was to create a custom drupal module that looks to see if ".." is in the URL. If the ".." string is found, then I have it set to redirect to the url without ".." in it using built-in drupal functions. Here is the code I used in my module.
function doubledot_fix_init() {
$destination = drupal_get_destination();
$alias = drupal_get_path_alias($destination['destination']);
$fixpath = str_replace("..", "", $alias, $count);
if ($count > 0) {
drupal_goto($fixpath, array(), 301);
}
}
I do not see any reason this fix will break anything, because ".." should never really be found in any URL. If anyone can think of a situation that this fix could cause an issue, or if you know of a better solution, please let me know.

Apache htaccess spanish accent

I have a problem with a redirect rule that doesn´t work with spanish special characters. I dont know how can i convert my word to type into the htaccess file, because the charset supported by htaccess file doesn´t recognice de Á, É, etc characters. Do you know can i set the redirect rule for something like:
Redirect 301 /home/BÁSICO.pdf http://example.com/exampledocument.pdf
or
Redirect 301 /home/MÉDICOS.pdf http://example.com/exampledocument.pdf
You can try this:
If you are editing the .htaccess file with Putty, you can try this with your keyboard: 1)accent key; 2)Shift+(A,E,I,O,U); 3)Space bar
With this method I did a similar redirection works fine.
Also exist other posibility. You can try to change all special characters with this "(.*)" in the RewriteRule.
Unicode is a little tricky - you may be better off with the encoded version:
Redirect 301 /home/B%C3%81SICO.pdf http://example.com/exampledocument.pdf
Redirect 301 /home/M%C3%89DICOS.pdf http://example.com/exampledocument.pdf
You can use this encode for assistance: http://meyerweb.com/eric/tools/dencoder/
Note: I have not tested this, but it is based off this question/answer.

Apache: Why on IE .htaccess rewrites non Latin character URLs to urlencode? How to solve it?

Apache: Why on IE .htaccess rewrites non Latin character URLs to urlencode? How to solve it?
domain.com//контакты rewrites to domain.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B
RewriteEngine On
# Rewrite multiple slashes with single slash after domain
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,NE,L]
Seems there still are no solution for IE and it depends of browser address-bar encoding.
Like Chrome 12 shows UTF-8 url domain.com/контакты, but on Ctr+C, Ctr+P you will get Unicode url http://domain.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D1%8B
#Pekka: Yes. On newest browsers any URLs has UTF-8 encoding. And they rewrites domain.com//контакты to domain.com/контакты, like it is excepted to be.
As far as I know, this is not entirely correct and this may be the reason why it doesn't work for you.
What new browsers are really doing is they show you the URL in its native form контакты, but internally still make the request in percent encoded form.
This seems to be the crux: You type something in, IE recognizes the Unicode characters, but the subsequent 301 redirect leads to a (correct) percent encoded URL. A modern browser will automatically "decode" the percent encoded URL; IE and older browsers might not.
I don't know whether there is a workaround for this. One thing you could try is have a PHP script do the URL rewriting, and have that script redirect to the (however invalid!) URLDecoded URL:
<?php header("location: http://example.com/контакты"); ?>
I have no idea whether this'll work, though.
Reference: Unicode characters in URLs
Related IE setting

How to use spaces in the URL path in mod_alias’ Redirect directive?

Following on from link text, I've also got problems with file paths that contain spaces. I was told to simply enclose the full path in quotes, and that should work, but I keep getting this page marked up in my Webmaster Tools error log as not being found:
redirect 301 /"News/Press Releases/Press_Release_Update_Oct_2006.pdf" /index.html
still gives me a 404.
Thanks Martin
Have you tried putting the quote before the /?
redirect 301 "/News/Press Releases/Press_Release_Update_Oct_2006.pdf" /index.html