Forum Moderators: open
I am building an index of some sort, based on a MYSQL db. I rewrite my URLs using Apache's mod_rewrite.
Right now www.mysite.nl/directory and www.mysite.nl/directory/ (<-- note the /) both show the same page.
Is there a 'best practice' with regard to the use or omission of the forward slash at the end of a URL?
If both URLs work, could that be seen as content duplication? It did take a while for Adsense ads to appear on the URL without the /, so perhaps the Mediapartners bot sees them as different pages?
Should I have both URLs display the same page or only the URL with or without the forward slash?
I see DMOZ and YAHOO automatically add a / if it is omitted. Is this default server behaviour or is it programmed?
www.mysite.nl/directory and www.mysite.nl/directory/ are different addresses. If Apache does not find a file "directory" it will look for a directory "directory" so more work for the server is involved.
The addition of the missing slash is both programed and default. In that Apache has to be set up to do it but I think that set up is in the default installation.
There's much more to it than this, spending some time with the Apache docs or a good Apache book is a worthwile thing to do to get to grips with the application's behaviour.
I see DMOZ and YAHOO automatically add a / if it is omitted. Is this default server behaviour or is it programmed?
One would hope they are responding to 301 Moved permanently HTTP replies.
Omitting the "/" can cause a redirect at the server. Although the server can be configured to deal with this so that it doesn't send a redirect, it will involve more CPU cycles. Also, the HTML you write should be independent of the server implementation. So, one server might not do the redirect, but if the code moves to another server, it might have to do the redirect.
One exception to this is the root resource. That is, if you have a URL of "http://www.example.com" then the HTTP specifications dictate that the browser send the request just as if it had been written "http://www.example.com/". As others have said, for the root, you should pick one method or the other and stick to it.
Google and other search engines will attempt to equate the two anyway (for purposes of page rank), but better to control it yourself as much as possible.
py9jmas are you suggesting a 301 moved permanent is best for this situation. If so, why?
Longhaired Genius. I'd love to read a book on Apache and I am planning to do so. If you have a suggestion for a good book I'd be happy to hear it as I am going on vacation on a week and I'll have plenty of time for reading then.
I have my URL rewriting for first level directories like this now:
RewriteRule ^([a-zA-Z]+)$ [mysite.nl...] [R=301,L]
RewriteRule ^(.*)/$ getcontent.php?cat=$1 [L]
The first rule catches "mysite.nl/directory" and sends it to "mysite.nl/directory/" and the second one catches "mysite.nl/directory/" and sends it to getcontent.php. Works like a charm. I hope you agree with this setup.