Is a trailing slash appropriate before URL parameters?

12,110

Solution 1

All four of your URLs are different for SEO:

  • http://www.example.com/product
  • http://www.example.com/product/
  • http://www.example.com/product?source=googleps
  • http://www.example.com/product/?source=googleps

It doesn't matter which one of those four you use, but you have to pick one and use it consistently. Both slashes and parameters create new URLs to search engines. Serving the same content with different URLs can cause search engine crawlers to do extra work and not crawl, index, and rank your site efficiently.

You can use several tools to combat this:

  1. Redirect all duplicate URLs to your preferred "canonical" URL.
  2. Use the link rel canonical meta tag to tell the search engines which one to use.
  3. Use the "URL parameters" setting in Google Webmaster Tools to tell Google that the "source" parameter doesn't change the page content (it is only used for tracking).

Both versions of your URL with parameters are "legal". The trailing slash can be there if you choose, or you can omit it. Use whichever is easier for you to configure on your server and use your choice consistently.

Solution 2

Regarding the SEO, I wouldn't expect it to be an issue, as Google have enough common sense to realise that, if the two URLs you have shown returned the same content, that for all practical purposes the URLs the same to a human.

In fact some webmasters/developers will write brief rewrite rules to append or remove the slash because "it looks nicer".
These rewrites may be internal HTTP server redirects (which are not visible to external user agents) and for Google to "expect" webmasters to code a dedicated redirect and corresponding round trip communication between server and user-agent which "announces" a redirect (and therefore a canonical URL) - e.g. a HTTP response with 30x and a "Location: [old URL except with a slash on it]" - and punish those who dont - doesn't make much sense.
However I don't work for Google so I couldnt say for sure - I just personally would bother with it, and you can always specify the canonical URL using the "rel" canonical tag.

If the URLs deviated any more and still returned the same content, e.g.

  • http://www.example.com/product.html
  • http://example.com/product/

Then I would clean them up and specify canonical URL.

In my experience - with PHP - if the query string REQUEST_URI (portion of address following the HTTP_HOST which contains the REQUEST_URI and the QUERY_STRING) has a slash or not - PHP doesnt seem to care - the slash will be captured in the $_SERVER['REQUEST_URI'] array key and the query string in the $_SERVER['QUERY_STRING'] key

Share:
12,110

Related videos on Youtube

Jeepstone
Author by

Jeepstone

Updated on September 18, 2022

Comments

  • Jeepstone
    Jeepstone over 1 year

    I understand that

    http://www.example.com/product
    

    and

    http://www.example.com/product/
    

    can actually be seen as 2 different URLs and is probably best avoided for SEO purposes, but how does this affect querystring parameters. Which is better (or even 'legal')?

    http://www.example.com/product?source=googleps
    

    or

    http://www.example.com/product/?source=googleps
    

    Do you need the trailing slash before the ?

    • unor
      unor about 9 years
      Related question on Stack Overflow: Trailing slash before a query string. Bad practice?
    • MrWhite
      MrWhite about 9 years
      "can actually be seen as 2 different URLs" - They are 2 different URLs, so it may be entirely dependent on your config whether you need to specify the trailing slash or not.
  • MrWhite
    MrWhite about 9 years
    "if the query string has a slash or not" - in the example it's the URL-path that has a trailing slash, not the query string and this is really dependent on the server, rather than PHP, whether it resolves or not (although that could depend if the URL is being rewritten).
  • the_velour_fog
    the_velour_fog about 9 years
    yes, if the web server and the CGI process manager, as the upstream HTTP request handlers, don't consider the request to be be valid, or dont pass on the params as expected because of the / then, yes the response from PHP or whichever server-side platform you are running - may be irrelevant. But in order to successfully fulfil the request all the components in the web stack have to process it properly
  • Jeepstone
    Jeepstone about 9 years
    Thanks Stephen for the edit and the most appropriate answer. Whilst I picked up on the SEO element, it was more the legality of the URL.