Remove trailing slash .htaccess

Hi Guys!

How do I remove trailing slashes for all urls on my subdomain (i.e. http://subdomains.mydomain.com/link-to-article/

Thanks in advance,


Options +FollowSymLinks -Indexes -MultiViews

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^subdomains\\.mydomain\\.com$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

:slight_smile:

Hi, thanks for your reply.

I tried those rules in my htaccess file but it didn’t work.

Here is my current file:


Options +FollowSymlinks
php_flag display_errors on
RewriteEngine on
RewriteRule company/(.*)/(.*).html viewjob.php?companyurl=$1&jobtitle=$2 [NC,L]
RewriteRule news/(.*).html news.php?newsurl=$1 [NC,L]
RewriteRule industries/(.*) directory.php?type=industry&url=$1 [NC,L]
RewriteRule locations/(.*) directory.php?type=location&url=$1 [NC,L]
RewriteRule job-types/(.*) directory.php?type=jobtype&url=$1 [NC,L]
RewriteRule company/(.*) directory.php?type=company&url=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^subdomain\\.mydomain\\.com$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Any idea what could be wrong?

Yes, you need to replace subdomain\.mydomain\.com with the actual domain you want to use it on :slight_smile:

Yes, sorry I did that too, just didn’t want to post it here - sorry I didn’t make that clear :slight_smile:

Would your code work for:

http://subdomain.mydomain.com/directory/electro-mechanical-design/

It should work on anything that is not directory and it works fine for me. Are you sure you’ve entered the domain correctly?
(if you don’t want to share the domain in public you can also PM me with the full .htaccess if you wish)

A good place to know about htaccess and urls is here : Url propres avec .htaccess, it gave me a good working solution about clean slug urls.