htaccess redirection issue with greek characters - .htaccess

.htaccess direction issue....
Redirect 301 /fr/cours /fr/cours-apprendre-le-grec-à-athènes
does not seem to work. I guess it's that using aphostrophes? like à that messes things up. How could I get the direction to work?
It's supposed to redirect to http://www.lexi-logos.gr/fr/cours-apprendre-le-grec-%C3%A0-ath%C3%A8nes when typing http://www.lexi-logos.gr/fr/cours
but instead it redirects to
http://www.lexi-logos.gr/fr/cours-apprendre-le-grec-%E0-ath%E8nes
Other redirections does work on the site, so the rewriting works.

This may be a local file encoding issue. You can try being explicit with the URL encoding:
Redirect 301 /fr/cours /fr/cours-apprendre-le-grec-%C3%A0-ath%C3%A8nes
Specifically, %E0 is the Windows-1252 version of the à character and %C3%A0 is the UTF-8 version. The htaccess file may be interpreted to be Windows-1252 charset so apache is encoding it incorrectly.

Related

.htaccess redirect shows multiple %20 when URL contains space on HTTPS

I have some old URLs that I need redirected, unfortunatelly some of them contain spaces. I redirect them to my redirect.php script, but for some reason when the URL contains space or %20, in the URL after redirection this %20 repeats unlimited times. This seems to only happen now when we switched the server to HTTPS, when running on http subdomain or on my local it works correctly.
My rule is:
RewriteRule ^/?(gallery\.php)(.*) /redirect.php$2 [R,L]
This works correctly:
gallery.php?place=name --> redirect.php?place=name
But this happens when url contains space:
gallery.php?place=long%20name -->
redirect.php?place=long%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20name
I tried adding [B] and [NE] flags but no success. Is there anything I am missing?
UPDATE 1:
To exclude other rules in htaccess, I have created a new example. I have empty directory /test/ , inside is empty file /test/index.php and /test/.htaccess file, which contains:
RewriteEngine On
RewriteRule ^/?(index\.php)(.*) /$2 [NE,R,L]
That is all. Still the behaviour is weird, eg:
/test/index.php?a=xy works as expected, but /test/index.php?a=x%20y repeats the %20 sign.
So in the end I managed to go around the problem by reordering the .htaccess rules. So I do all redirects from HTTP to my redirect script which is on HTTP as well. This script then resolves the correct new URL, that is already on SSL without spaces, and then the script redirects there. Fortunatelly all old URLs are on HTTP so it is sufficient, I don't need this parameter redirects to happen on SSL.
Also the [NE] flag is helpful when redirecting URLs with %20, as it prevents the percentage sign to be further encoded in new URL.

What is wrong with this rewrite rule?

Here's the rule in my .htaccess file:
RewriteRule ^add/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ add.php?link=$1&email=$2 [PT,L,QSA]
Here's the link that won't work (page not found):
http://www.example.com/add/http%3A%2F%2Fwww.example.com%2F/web%40web.com
Here's the version that will work (although not in the format I am hoping for):
http://www.example.com/add.php?link=http%3A%2F%2Fwww.example.com%2F&email=web%40web.com
How do I fix this rewrite rule?
Your regex i.e. [A-Za-z0-9-] not match %3A, %2F etc, try this:
Options -MultiViews
RewriteEngine On
RewriteRule ^add/(.+)/([^/]+)/?$ add.php?link=$1&email=$2 [NC,L,QSA]
Also %2F is not allowed in Apache by default. Use
AllowEncodedSlashes Decode
in your Apache config to allow it otherwise Apache will throw 404 if there are any %2F in URL even before mod_rewrite is invoked.
Ok, I have solved this problem and it took a great deal of research as I'm not as talented as some people on here. I thought I'd share the solution anyway.
Essentially the server will prematurely decode %2F as soon as it is used, so you end up with a path that is totally wrong.
What you have to do is replace %2F with %252Fat the client side.
This is the double encoded form of %2F.
So when it reaches the server it prematurely gets decoded to %2F instead of a forward slash.
You're welcome.

Need redirect old url to new friendly url

a need redirect
http://www.mysite.com/product.php?id_product=216
to
http://www.mysite.com/category/newProduct.html
I try to add a line in htacces
redirect 301 /product.php?id_product=216 http://www.mysite.com/category/newProduct.html
but dont work.
If I add
Redirect /product.php http://www.mysite.com/category/newProduct.html
All links like
http://www.mysite.com/product.php
http://www.mysite.com/product.php?id_product=216
http://www.mysite.com/product.php?id_product=219
Go to homepage http://www.mysite.com/
Any idea. THX
Check the following:
Make sure your file is called .htaccess, not htaccess as you say above.
If you're using FTP to transfer it to the server, use ASCII rather than binary transfer mode.
Make sure the .htaccess file is in a directory where the Apache AllowOverride directory option is on if you're using apache web server.

301 redirect using regular expression in .htaccess

I have suddenly been hit with hundreds of 404 crawl errors to pages which must have been on a previous site (though I thought I'd got them all...). It's a bit strange as I've never seen any page with index.php in it, yet all the errors start with index.php/xxxxx.
So, I want to do the following:
redirect 301 index.php/<wildcard> http://www.example.com
in the .htaccess file.
Can someone tell me whether this is correct, and what I have to put in the <wildcard> place if it is? If this is incorrect, what is the code to accomplish this?
You can use a the Redirect directive in the htaccess file and do a simple regular expression assuming your site doesn't use /index.php/query/parameters like some PHP frameworks do.
Redirect 301 /index.php/(.+) http://www.mysite.com

.htaccess Redirect on a url with spaces in it

I have a link from anther website that I do not have control of http://example.com/one two three.exe
The correct URL is http://example.com/one_two_three.exe
Note the underscores instead of spaces.
I searched the internet and found this code snippet for .htaccess
# Redirect old file path to new file path
Redirect /one%20two%20three.exe http://example.com/one_two_three.exe
I added this snippet to my preexisting root .htaccess at the top of the file.
But it does not seem to work. My browser does not redirect and I get a 404 error page.
I believe that it has something to do with the spaces in the original URL but I don't know how to handle spaces in the URL.
Suggestions?
You could try a couple of things (both untested)
Redirect "/one two three.exe" http://example.com/one_two_three.exe
or use RewriteRule instead of Redirect:
RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe

Resources