Reputation: 385
I've been looking into standardizing all of my sites URLs before I launch (For obvious reasons), and have been doing a lot of research on the subject. I've come to the following conclusions:
It does not matter if you use a forced trailing slash or forced no trailing slash, as long as you don't have multiple URLs for the same page.
It looks better, and makes more sense for a lot of people if directories/collections (I.e. posts/ or articles/) have a trailing slash, while "files" or specific items (An article or blog post for instance) don't (I.e. posts/2012-02-05-Stackoverflow-rules or articles/12-Proper-URLs).
Now I'm obviously open to debate / other opinions on this subject, but right now I'm leaning towards this method of URL... With that said, what would be the best way to force this standard? My system is based on modules, I have no idea how many modules I will have and I would really rather not edit the .htaccess file with a new mod_rewrite rule for every new module I (Or someone else) adds - that just gets messy.
Is there some easy, sure-fire way to do this without htaccess, in PHP? Do I even need to? All of the URLs are going to be generated by a single class which will reinforce those standards, and this is a proper MVC framework - so adding some code for pages that don't match the standards above wouldn't be all that difficult - but I'm just not sure what the best way to do it would be.
Clarification
Edit To clarify, I'm trying to figure out how to make some links have trailing slashes, and some links not have trailing slashes*, and if someone links to the wrong URL (No trailing slash on a URL that needs to have one, or vice versa) it will redirect the user to the proper url.
*An example would be
For pages that need a trailing slash, and
For pages that shouldn't have a trailing slash. Basically "directories" have slashes and "files" don't.emphasized text
So basically, what would be the best way to accomplish this? Obviously all internal links will meet this standard, but I am unable to control other sites - and them linking with or without a trailing slash may hurt my SEO. And on a related note, what is your opinion on this style of URL?
Upvotes: 1
Views: 2010
Reputation: 12721
Whether you have them or not is mainly a matter of convenience for you. You should be consistent and make sure their is only one "true" URL per page. As far redirects, I would recommend not redirecting just because there isn't or is a trailing slash. The redirect is just overhead in those cases.
Use the canonical meta tag to indicate to search engines what the "true" URL is. I usually create a centralize function that can check the current URL against some rules an generate the "true" canonical URL. If your centralized function is getting too large or has too many rules, your URL structure is probably too complicated.
Upvotes: 2
Reputation: 906
We recently had the same issue. We decided to go with / after everything except pages where there might be ?query_data. It made our detection allot simpler. Just check that a trailing slash exists at the end unless ? We used PHP to do this. Im sure there is an .htaccess approach too. Its going to be one of those, whatever works best for your scenario. You might want to take a look into canonical tags also, as well as proper 301 redirects ( http://en.wikipedia.org/wiki/HTTP_301 ) this will keep your search engine records clearer too.
Upvotes: 0