Redirect to URL with umlauts or accents via .htaccess - .htaccess

To redirect to a new URL that contains diacritics via .htaccess, what is the correct and safe way?
Can I somehow set the .htaccess file to UTF-8 and just use the non-ASCII characters, e.g.:
redirect 301 / http://www.bücher.ch/
Need I use the ACE string instead, e.g.:
redirect 301 / http://www.xn--bcher-kva.ch/
Is urlencode the way to go? I tried the following without success:
redirect 301 / http://www.b%C3%BCcher.ch/
For context, the following page on internationalized domain names (IDN) has a section about the technical solution to include accents and umlauts in domains.

In the domain part, you must use ASCII Compatible Encoding (ACE).
In the rest of the URL, you use urlencode. So, in .htaccess…
http://www.bücher.ch/schöne/
…needs to be written as…
http://www.xn--bcher-kva.ch/sch%C3%B6ne/

Related

URL Redirection if only certain URL is matched htaccess

I have a very small and odd issue. I want to write a rule which allows me to redirect URL.
https://www.example.com/category/florists/
to
https://www.example.com/category/florists.html
but to keep in mind there are other URLs which will be made from the above like
https://www.example.com/category/florists/fl/miami.html
I wrote a rule in .htaccess but it is causing trouble to later URLs
Redirect 302 "/category/florists/" /category/florists.html
this rule works fine but for this URL
https://www.example.com/category/florists/fl/miami.html
it makes it like this
https://www.example.com/category/florists.html/fl/miami.html
how can I solve it?
The mod_alias Redirect directive uses simple prefix-matching and everything after the match is copied into the end of the target URL (which explains your undesirable and malformed additional redirects).
To match just that one URL you need to use a RedirectMatch directive instead which matches against a regular expression (not prefix-matching).
For example:
RedirectMatch 302 ^/category/florists/$ /category/florists.html

Redirect old url to new url with .htaccess redirection

I am trying to redirect all of the following type of links:
LINKS TO BE REDIRECTED:
https://www.canvas-events.co.uk/venues/landmark-buildings
REDIRECT TO THIS LINK DYNAMICALLY:
https://www.canvas-events.co.uk/hire/venues/landmark-buildings
NOTE: I want to redirect all url's which contains alphabets naming instead of integers because we have an another route which has the same route structure too, i.e. venues/293 & /venues/landmark-buildings the only difference is the use of alphabet based delimiter instead of integer one. I need to redirect the link with alpahbets delimiter not the integer one.
Thanks
This should work :
RedirectMatch 301 ^/venues/([A-Za-z/-_]+)/?$ https://www.canvas-events.co.uk/hire/venues/$1
The pattern above only accepts characters ranging from A-Z a-z and some URL characters / -_ .

String replacement with htaccess?

Some of my sites sometimes get encoded url queries which will redirect to a error page but i would like to support some of these.
With htaccess how could you replace a url like this:
http://website.com/%3Fpage%3Dbdyb2y21ybar3h35
With this:
http://website.com/?page=bdyb2y21ybar3h35
Edit: I would like to do this directly within the .htaccess rather than decode with PHP etc.

htaccess redirect url with space in it

Stupidly, I have sent out a newsletter without checking the links. One of which is broken so I want to handle this with htaccess.
My URL that is being linked to is:
http://www.domain.com.au/www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/
where the actual page is:
http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Note the space in new zealand as well as the additional www.domain.com.au
How can I set this up in htaccess?
Thanks
Since you don't have to manipulate the URL, you can use a simple Redirect:
Redirect /www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/ http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Edit If Apache doesn't like the space unquoted as %20, try quoting the whole thing with a real space in there:
Redirect "/www.domain.com.au/campers-and-motorhomes/ne w-zealand/camper-rentals/" http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/
Edit2 If it's appending a query string, you will need to use mod_rewrite to get rid of the querystring rather than a simple redirect, I'm afraid.
RewriteEngine On
# If the request starts with www.domain.com.au, it is the broken link
# Rewrite to the proper URL and put ? on the end to remove the query string
RewriteRule ^www\.domain\.com\.au http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/? [L,R=301]

.htaccess 301 redirect not redirecting to the French urls properly

I am using a 301 redirect command in .htaccess file
Redirect 301 /fr/emergency http://www.sitename.com/fr/d’urgence
But on redirection the url has turned out to be http://www.sitename.com/fr/d%92urgence and shows a page not found error.
The requirement is that it needs to come as http://www.sitename.com/fr/d’urgence itself.
Any idea what needs to be corrected and where?
The string should be encoded in UTF-8 and then percent encoded. You should never use non-ASCII characters in a URL sent over the wire (at least, not yet... someday), and this is the way around it.
Redirect 301 /fr/emergency http://www.sitename.com/fr/d%E2%80%99urgence
A web browser will still display it as d’urgence, the user will never see the percent-encoded version. This assumes that the ’ character is actually supposed to be U+2019 "right single quotation mark" and not U+0027 "apostrophe".

Resources