1

I've found this post (https://stackoverflow.com/a/21417551/2722571) which works to add a trailing slash using the code:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]

However, it breaks when submitting a contact form which requires a specific URL without a trailing slash.

/wp-json/contact-form-7/v1/contact-forms/1593/feedback

All forms use the same pattern up to the form id, i.e. this part is always the same:

/wp-json/contact-form-7/v1/contact-forms/

How do I amend the rule to ignore the above pattern URL whilst still enforcing the rest of the rule?

I've tried a few variations of the above rule like this, but it doesn't work and it either ignores the whole rule or throws an error. One example of what I've tried is below:

RewriteCond %{REQUEST_URI}!^/wp-json -d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R] 

PS. I am not a htaccess expert so not sure if the above rule is valid or what its doing exactly.

  • Try `RewriteCond %{REQUEST_URI} !^/wp-json` This checks that the originally requested URI does not start with `/wp-json` – CBroe May 07 '20 at 11:04
  • You and Anubhava both gave similar solutions, but there is something about the additional [NC] stuff that he's added that makes his version work. Not sure why, but thanks for your help!! – Unbranded Manchester May 07 '20 at 12:09

1 Answers1

1

You may use this rule:

RewriteCond %{THE_REQUEST} !/wp-json/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643