Custom Search
|
|
Why Add Slash To End Of Url
Note that this for directory only, not for urls with file names. Why add a trailing slash on directory url? This is because without the slash, the browser will initially try to retrieve a file rather than a directory. When the server realizes that "mystuff" is a directory will it direct the browser to add a slash to the end of the URL and try again. Whilst this doesn't seem too much of a problem, it will slightly increase your bandwidth usage every time it happens, so if you're running a high-traffic site, it's worth adding in those closing slashes. Take "http://www.mywebsite.com/mystuff" this as an example url. First server would try to find a file called mystuff in the root website directory. If not found it MIGHT add a trailing slash to treat it as a directory and try again. Some servers are nor forgiving Some servers are not that forgiving without trailing slash for directory urls. They will simply treat it as file, and when not found would show 404 Page Not Found or Page Cannot be Displayed error. Best Practice If you are on Linux server you can use .htaccess file to add the trailing slash on directory urls. Here are some ways to accomplish this. RewriteEngine On RewriteBase / RewriteCond %REQUEST_FILENAME !-f RewriteCond %REQUEST_URI !index.php RewriteCond %REQUEST_URI !(.*)/$ RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301] or RewriteCond %REQUEST_FILENAME !-f RewriteCond %REQUEST_URI !\..+$ RewriteCond %REQUEST_URI !/$ RewriteRule (.*) http://www.mydigitallife.info/$1/ [R=301,L] or RewriteEngine On RewriteBase / RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [L] RewriteCond %THE_REQUEST ^[A-Z]3,9\ /([a-zA-Z0-9]+) RewriteRule ^([a-zA-Z0-9]+)$ /%1/? [R=301,L] Article Directory: http://www.articledashboard.com Webmaster of Webcosmo Webmaster Forum. |
|
© 2005-2011 Article Dashboard