0

I have single htaccess file for many domains and I need to force a trailing slash at the end of my url for a specific domain only.

I have tried the existing rewrite conditions and they work globally I just need a domain specific solution.

RewriteEngine on
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • *"force a trailing slash at the end of my url for a specific domain only"* ... then you'll need to target that specific domain in the RewriteCond – CD001 Oct 04 '19 at 12:06

2 Answers2

1

you can do this :

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

seems duplicate question : Add Trailing Slash .htaccess

S.Kashizadeh
  • 563
  • 4
  • 14
  • If it's a duplicate it should be closed as such ... but in this case I think the specific domain requirement (e.g. you need to do a RewriteCond match on `%{HTTP_HOST}`) means it's not *quite* a duplicate of the answer you're linking to ;) – CD001 Oct 04 '19 at 12:10
0

Try changing the Request_URI with actual domain

Maybe like this:

RewriteEngine On
RewriteCond %www.example.com /+[^.]+$ 
RewriteRule ^(.+[^/])$ %www.example.com/ [R=301,L]
Avinash Karhana
  • 659
  • 4
  • 16