Search code examples
wordpress.htaccess

Url without trailing slash needs to redirect to URL with trailing slash


I have a WordPress site. The URL example.com/he/ loads the correct page but example.com/he shows a Page Not Found Error. What do I need to add to the .htaccess file to make example.com/he redirect to example.com/he/? I tried

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

but nothing happens.


Solution

  • If always the same directory you can just add this line to your htaccess in order to redirect URL without trailing slash to URL with trailing slash.

    RewriteRule ^he$ /he/ [L,R=301]
    

    If you have other directories you may declare each one after another.