Welcome Guest, Not a member yet? Register   Sign In
Should URL's end in a trailing slash?
#1

[eluser]Xeoncross[/eluser]
I have been forcing trailing slashes into all my paths since starting with CI. For example:

Code:
site.com/
site.com/welcome/
site.com/profile/

Thanks to some nice mod_rewriting:

Code:
#  Forces trailing slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+)$ $1/ [L,R=301]

However, given the old adage that "directories end in slashes, while files don't" I started questioning my method. After all site.com/profile/ isn't a directory - it's a page. So I am now changing to removing ending slashes from all my pages.

Code:
# Removes trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule ^(.+)/$ $1 [L,R=301]

Any input on which one is the proper method? I really would like to pick one and stick with it.
#2

[eluser]Colin Williams[/eluser]
It's a moot issue when using something like mod_rewrite because the server is instructed to always hit index.php, trailing slash or not. The problem with leaving off the trailing slash (without mod_rewrite doing its directing) is that the server would need to attempt a redirect to the forward-slashed path in its attempt to serve the request. And I don't think search engines put any weight into it.
#3

[eluser]Xeoncross[/eluser]
I assume that you're referring to this:

Code:
# Do not add an ending slash to directories (/)
DirectorySlash Off




Theme © iAndrew 2016 - Forum software by © MyBB