Mod_rewrite trailing slash with RewriteCond

I looked at the related mod_rewrite qustions, but I can’t do anything specific, so I will post:

Here is my rule that adds a trailing slash:

RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Only I want to exclude one specific directory, for example. / mydirectoryname / and don't add a trailing slash to anything that starts with this. The reason is because it breaks some of my ajax calls.

+3
source share
2 answers

Add another RewriteCond:

RewriteCond %{REQUEST_URI} !/mydicrectoryname)/

+3
source

You can describe this with only one condition:

RewriteCond $0 !^mydirectoryname(/|$)
RewriteRule ^[^\.]+[^/]$ /$0/ [R=301,L]
+2
source

Source: https://habr.com/ru/post/1724941/


All Articles