Support » How-To and Troubleshooting » Handle Trailing slashes at the end of URL

Handle Trailing slashes at the end of URL

  • There is clear cut advantage of using consistent URL structure for wordpress website.

    I want all of my URL’s to end with / (the homepage and internal page URL’s). Let me give an example website which is handling it very efficiently so that the URL’s without ending with slash or ending with multiple slashes are 301 redirected to URL with single slash.

    http://viralpatel.net/blogs 301 redirect to viralpatel.net/blogs/

    http://viralpatel.net/blogs// 301 redirect to viralpatel.net/blogs/

    http://viralpatel.net/blogs/ 200 OK

    http://viralpatel.net/blogs/check-string-is-valid-date-java 301 redirect to http://viralpatel.net/blogs/check-string-is-valid-date-java/

    http://viralpatel.net/blogs/check-string-is-valid-date-java// 301 redirect to http://viralpatel.net/blogs/check-string-is-valid-date-java/

    http://viralpatel.net/blogs/check-string-is-valid-date-java/ 200 OK

    Any idea what .htaccess rules can help achieve this. My current .htaccess looks like:

    RewriteEngine On
            RewriteCond %{HTTP_HOST} ^javaexperience.com [NC]
            RewriteRule ^(.*)$ http://www.javaexperience.com/$1 [R=301,L]
            RewriteBase /
            RewriteRule ^index\.php$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.php [L]
  • The topic ‘Handle Trailing slashes at the end of URL’ is closed to new replies.