简体   繁体   中英

Trailing slash redirect based on url

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]

you can do this:

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

seems duplicate question: Add Trailing Slash .htaccess

Try changing the Request_URI with actual domain

Maybe like this:

RewriteEngine On
RewriteCond %www.example.com /+[^.]+$ 
RewriteRule ^(.+[^/])$ %www.example.com/ [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM