SEO issue and remove a trailing slash from URL - seo

We have a web site written in ASP.NET. When you open the following page:
http://concert.local/elki/
You can see the slash "/" at the end. We need to remove it in order to have:
http://concert.local/elki
I've tried some things to make it work, but it doesn't help. For example, when I add the following code in Global.asax.cs file:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().Contains("http://concert.local/elki/"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://concert.local/elki/", "http://concert.local/elki"));
}
}
The following error comes up:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
There is also the following code:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentHead">
<link rel="canonical" href="http://concert.local/elki" />
</asp:Content>
That puts canonical stuff in page header.
How can I get the following URL:
http://concert.local/elki
?

Check out this answer: url trailing slash and seo
It basically says that Google prefers the trailing slash. Just code consistently and you should be fine.

Here is the official answer from Google. Effectively, they dont care whether you have a trailing slash or not
http://googlewebmastercentral.blogspot.fr/2010/04/to-slash-or-not-to-slash.html
Google treats each URL above separately (and equally) regardless of
whether it’s a file or a directory, or it contains a trailing slash or
it doesn’t contain a trailing slash.

Related

Url with trailing slash is redirected back to the host url

i have sales channel with the domain "http://tld.de/staging" and only this domain, the only other sales channel is the default headless sales channel.
I created a custom route like that:
#Route("/path", name="frontend.path.index", options={"seo"="false"}, methods={"GET"})
And it works just fine when using the url http://tld.de/staging/path but when I use the url http://tld.de/staging/path/ (with trailing slash) it redirects me to http://tld.de/path
I already tried to add a second route for that method but that didn't work
#Route("/path/", name="frontend.path.index.trailing_slash", options={"seo"="false"}, methods={"GET"})
Did I miss something or is that just the default behaviour?
Additional information: The custom controller class extends the StorefrontController and there are not redirects happenening inside of the custom controller, I even added a dd() at the beginning of the method for testing. And If i add the trailing slash to the first route the url with the trailing slash works but the one without gets redirected instead.
The redirect of the url with the trailing slash to the one without is the default behavior of Symfony. If that redirect doesn't respect your base path, then it's probably an issue with your configuration.
However if you absolutely must serve both URLs without redirecting, then you could use wildcards to do so. Obviously this is unconventional but should work:
/**
* #Route("/path{trailingSlash}", name="frontend.path.index", methods={"GET"}, defaults={"trailingSlash"="/"}, requirements={"trailingSlash"="[/]{0,1}"})
*/

URL with trailing slash does not load scripts and CSS in PHP site

what is the difference between these two URLs:
abc.com/company-profile.php
abc.com/company-profile.php/
When I directly open the first one (without trailing slash) the page open perfectly.
But when search it in Google I get the second link (with trailing slash) and when I click on this link, the page only shows code, no script or css included.
After clicking on any style.css, the page shows like abc.com/company-profile.php/css/style.css.
What is happening?
The cause can be that Google indexes your website with a sitemap.xml file having the company-profile.php/ url and not company-profile.php.
And unfortunately your website doesn't manage well the trailing slash at the end of the url (you can fix this with updating .htaccess file)
You have to check the sitemap generated and downloaded by Google.
The url's sitemap name differs according you are using Wordpress, Drupal or another CMS, or a custom website...

express appending trailing slash to my static files

Somehow I got my express app into a broken state where it's appending a trailing slash to all static file requests. I'm using this:
app.use([/^\/api*/, '/*'], express.static(path.resolve('./public/dist'), { maxAge: 86400000 }));
Whenever a request comes in for a found resource (e.g. JS file), express appends a slash, causing browser to think it's an HTML file.

404 error when in ulr without slash in end

I use this url http://localhost/backend/backend/page/index, that it goes to 404 error page, but when I add / in the end of url, it works correctly.
I mean this url: http://localhost/backend/page/index/
Of course this problem is just for one of my urls. Other urls works without slash in ending url.
I have to add this, that the same url, that I have the same codes on another project, works without problem, and I don't need to add / in end of url. The problem is just in this project.
I use no urlmapping in my codes.
If you need more information, ask it.

Double slash at beginning of javascript include

I have been looking at the html5 boilerplate and noticed that the jquery include url starts with a double slash. The url is //ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
Why is the http: missing?
I hate answering with a link but this explains it - http://paulirish.com/2010/the-protocol-relative-url/
Using a protocol relative URL like "//mydomain/myresource" will ensure that the content will be served via the same scheme as the hosting page. It can make testing a bit more awkward if you ever use FILE:// and then some remote locations as they will obviously resolve back to FILE. Never the less it does resolve the mixed insecure/secure content messages you can cause by not using it.
So that if the .html is accessed via HTTPS; the page will not have any unsecured script.