The trailing slash in home page - .htaccess

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.

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

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.

Magento category urls infinite redirect

In Magento, I currently have on the site category urls which have no trailing slash, i.e. www.example.com/gifts
I want to change category urls to have a trailing slash, such as www.example.com/gifts/
To do this I went into the admin section, and edited the SEO section under system -> Configuration -> 'Catalog' -> Search engine optimizations.
There I added a '/' in the Category URL Suffix box.
That is all standard, and after rebuilding the index, the site does indeed display all category urls with a trailing slash, e.g. www.example.com/gifts/
The problem is, when I click on www.example.com/gifts/ (or any category now), I get an infinite redirect loop.
Chrome says "Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.", and doing a CURL -I -0 on the url shows a 301 redirect to Location: /gifts/.
I have checked my htaccess file, and there are definitely no rules related to trailing slash or category redirects.
EDIT: I have logging enabled on htaccess too, and I keep getting lines like:
strip per-dir prefix: /var/www/blah/app-core/index.php -> index.php
Is that normal?
Has anyone seen this issue before, or have any idea at all what might be causing this?
Its a complete blocker for me, so any insight or help would be very appreciated.
Thanks
Paul
Ha ha!!! Sorry, going a bit mad here!
Finally figured it out - I think it might be a bug in Magento 1.4.
In the Mage/Core/Model/Url/Rewrite.php file, request path is given as:
$requestPath = trim($request->getPathInfo(), '/');
So my request of '/gifts/' becomes 'gifts'. Magento then tries to append a slash, and it cycles over ad infinitum.
When you change the trim() to an ltrim(), it works. I.e.
$requestPath = ltrim($request->getPathInfo(), '/');
Now '/gifts/' is 'gifts/', and www.example.com/gifts/ is a 200!
Of course its a pain now to have to extend Magento just for such a minor tweak...
It sounds like your url rewrite table needs to be rebuilt. Login to your admin area and reindex the url rewrites.

htacces redirection if the url doesn't have .php extension

I wish to redirect all page requests if
(1) Current URL doesn't have .php extension
(2) Current Page is not the Site Home (ie www.site.com )
Example:
http://site.com/robin to profile.php?screen_name=robin
Can someone suggests the htaccess to accomplish this?
This site should give some hints:
http://www.webweaver.nu/html-tips/web-redirection.shtml
an excerpt from there:
Changed file extension?
This example is perfect if you've
decided to switch to .php from .html
pages. It will look for any .html page
and redirect it to .php (ie
http://www.example.com/yourpage.html
and redirect it to
http://www.example.com/yourpage.php).
Now, be careful with this, it does
mean any html page. I did this on one
of my sites and had totally forgotten
I had an iframe with .html content on
some pages... I didn't notice for
weeks that it was broken :S. So learn
from my mistake ;-) check, double
check, then check again.
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
You can put arbitrary regular expressions as parameter to Redirectmatch, so you need to add a regular expression which matches '".php" not last of line'. I am only a neophyte of RegExes myelf, so i do not provide an example yet. Check for a later update -have to do some experimating.

Resources