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]
Back to top

Fastest WordPress Hosting With WPEngine

Stunning speed, powerful security, and best-in-class customer service. At WP Engine.

Risk free for 60 days