in Web Development

Using htaccess To Force Trailing Slash

You can use htaccess to change the URL structure of your website. There are lots of things you can do with htaccess one of the most common things would be to make sure all the pages are prefixed with the www subdomain or to make sure all the pages are not prefixed with the www subdomain. Many people often say that they want their URL structure to always have a trailing slash at the end of the URLs. This can be done by using htaccess. If the URLs don't have a trailing slash the htaccess will redirect the browser to the URL with a trailing slash. Copy the following in your htaccess file to add a trailing slash to your website.

<IfModule mod_rewrite.c>
 RewriteCond %{REQUEST_URI} /+[^\.]+$
 RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email