Forum Moderators: phranque

Message Too Old, No Replies

URLs with "/" and without "/"

duplicate URLs with "/" and without "/"

         

arunrajiah

4:49 pm on Jun 6, 2012 (gmt 0)

10+ Year Member



Hi All,

I just went through my analytical tool and i found there are duplicate URLs like below

www.example.com/contact-us/

www.example.com/contact-us

one with "/" and another without "/".

I am using apache and im not sure if this is a valid URL. Please advise, if this is not a valid URL how can i avoid this? Do i need to write rules in .htaccess?

Thanks in advance

[edited by: arunrajiah at 5:20 pm (utc) on Jun 6, 2012]

g1smd

5:19 pm on Jun 6, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The canonical URL for a folder or the index page in a folder ends with a trailing slash.

The URL for a page does not end with a trailing slash, and may or may not have an extension.

The URL for a file (images, css, javascript, etc) nearly always has an extension.

These are defined in the HTTP specs.

You can redirect to remove trailing slashes for pages. The server should already automatically redirect (the DirectorySlash directive) to add a trailing slash for folders.

arunrajiah

1:41 am on Jun 7, 2012 (gmt 0)

10+ Year Member



Thanks for the details.

So if i access example.com/contact-us where contact-us is a directory it should redirect to example.com/contact-us/ am i right? But this is not working in my website. Whatever i give in the browser remains same, even if i give example.com/folder/image.jpg/ it is not getting redirected.

Please advice

arunrajiah

3:30 am on Jun 7, 2012 (gmt 0)

10+ Year Member



Also please let me know if i need write any rewriting rule in httpd.conf file to resolve this.

lucy24

5:32 am on Jun 7, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So if i access example.com/contact-us where contact-us is a directory it should redirect to example.com/contact-us/ am i right? But this is not working in my website. Whatever i give in the browser remains same, even if i give example.com/folder/image.jpg/ it is not getting redirected.

You're asking about two different and unrelated things.

mod_dir [httpd.apache.org] does two things.

#1 If you enter the name of an actual directory -- not a fake one that you create by rewriting -- it will make sure there is a / at the end. This is a full-fledged 301 Redirect, not a rewrite.

#2 After this happens, your requested directory will serve content from the file "/index.html" if there is one-- or any other filename you've told it to use. This is a rewrite, not a redirect.

Both of these are enabled by default. Apache warns strongly against turning off the directory-slash redirect. But you can change the list of filenames that it looks for as the default index: index.php, main.jsp or anything you like. Give the filename you actually use. (There is also auto-indexing, but you probably know how that works.)

Asking for a nonexistent file like "example.com/folder/image.jpg/" is something else again. There is no reason for a redirect, so by default the request will reach your server unchanged. And then, unless you have absolutely horrible filenames, you ought to be getting a 404 error.