.htaccess 301 redirect not redirecting to the French urls properly - .htaccess

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".

Related

How to make 301 redirect from one website to another where the ending is different?

I have 2 websites:
OLD one - https://www.old.example/en/
NEW one - https://new.example/en
Lastly, Google Search Console reported around 80 improperly redirected links for OLD website, i.e.:
https://www.old.example/en/?p=41310
https://www.old.example/en/?p=45659
https://www.old.example/en/?p=72785
In .htaccess of OLD page is inputted only code:
Redirect 301 / https://new.example/
which redirects above links from OLD page to i.e.
https://new.example/en/?p=62692
How can I correct it and i.e. expect to have in such cases always redirection to main page - https://new.example/en
To remove the query string completely (without a stray ? at the end) you'll need to use mod_rewrite instead.
For example, in the .htaccess at the old domain:
RewriteEngine On
RewriteRule ^(en)/ https://new.example/$1 [QSD,R=301,L]
Aside: Although this many-to-one redirect will likely be seen as a soft-404 by Google.

htaccess redirect with folder name

I need some help with htaccess redirects. Out site was wrongly crawled by google and as a result there are a lot of wrong urls being shown in webmaster tool. As an example:
articles/abcd/xyz
should be redirected as
articles/abcd/
articles/abcd/xyz.php
should be redirected as
articles/abcd/
articles/abcd/xyz.html
should be redirected as
articles/abcd/
So basically I am trying to mean always redirect to articles/abcd/ for varous wrong url types that i shown above. Please could you help
You can simply use RedirectMatch from mod_alias (documentation). We assume that the part after articles does not contain any / character. We redirect with a temporary redirect to the url without the suffix. Change "temp" to "permanent" after testing that this redirect actually works as you expect it to work.
RedirectMatch temp ^(/articles/[^/]+/).+$ $1

Redirect to URL with umlauts or accents via .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/

301 Redirect Issues in .htaccess file

I've been digging through the archives and threads and can't seem to find anything that matches my 301 Redirect issue -
I am trying to redirect old links to a new site and a problem with the following:
This one works - Redirect 301 /food-service/ http://www.xxxx.com/food-services.html
This one does not - Redirect 301 /food-service/distribution http://www.xxxx.com/distribution.html
The one that does not work tries to redirect to - http://www.xxxx.com/food-services.htmldistribution/
Would you mind lending me your thoughts on what I can do?
Thank you all!
The documentation for Redirect says:
Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.
The behaviour that you do observe is as we would expect from the documentation. It goes through the Redirect directives, and chooses the first one that matches.
To get the correct behaviour, you have to list the most specific redirect first, and the least specific last.
If you would have rules for /a/b/c, /a/b and /a, then you list them in that order.

The trailing slash in home page

I will be really greatful if someone helps me with this.
Let's consider these 2 URLs (both returning 200 in the response header):
www.foo.com/something
www.foo.com/something/
Google considers these 2 URLs different despite both having the same content which leads to a duplicated content problem. To solve the issue it is advised to either use the 301 permanent redirect to redirect one URL to the other or use the rel="canonical" attribute. source
Wordpress blogs deal perfectly with this matter. When adding the trailing slash to my internal links, I was redirected to URLs without the trailing slash (301 response).
The problem is the redirect is only happening with internal pages. My homepage seem to return a 200 response with or without the trailing slash. Should I leave it as it is or force a redirect with the .htaccess file?
p.s.: The backlinks to my website have 2 different hrefs (with and without the trailing slash). Should I change those backlinks to a unique href or redirect one to the other?
Use this link to add trailing slash to end of your url
It doesn't matter whether your Backlinks are with slash or not, because after implementing techniques mentioned in above address, search engines will assume your pages only with slashes. Remember because of past indexing you should wait until former index to be deleted. or you may use 301 redirect to pages with slash. Basically this will take some time until search engines came again and find your redirect rules, too... .
By home page I assume you mean the page shown when you enter just the domain.
With or without the slash represents exactly the same URL. Nothing to worry about and nothing you can do.

Resources