1

I have the following rules given in my .htaccess file everything works perfectly with only one exception:

#Active mod_rewrite
RewriteEngine on

#Name of APP
RewriteBase /web

#DirectorySlash Off

Options -MultiViews

#Remove web/ from URLs using a redirect rule
RewriteCond %{THE_REQUEST} \s/+(.+/)?web/(\S*) [NC]
RewriteRule ^ /%1%2? [R=301,L,NE]

#Disable WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#Active HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} assets/(css|fonts|js|img)/(.+)$
RewriteRule ^(.*)$ assets/%1/%2 [L,R]

#Add slash at the end (/)
#RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

RewriteRule ^([a-zA-Z0-9-/]+)$ product.php?id=$1

The error of that exception, is when I try to enable in the URL always the slash / end, by:

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

And, doing so, rules on file exclusions are lost

RewriteCond %{REQUEST_URI} assets/(css|fonts|js|img)/(.+)$ 
RewriteRule ^(.*)$ assets/%1/%2 [L,R]

And, even worse, when I try to access a product, it shows this in the URL

https://example.org/product.php/?id=mi-producto-de-url-amigable/?

All a mess, I have reviewed some articles, also by this means, I have tried the alternatives suggested in each post as RewriteRule ^(.*[^/]$) $1/ [R,QSA,L] and, among others but without success .

1 Answers1

0

Add Trailing Slash .htaccess

Have you tried this yet?

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 
magicfishy
  • 90
  • 8
  • It seems to work, I'm testing from the cell phone and, as noted, it works fine ;) –  Nov 06 '19 at 21:27
  • So now my question will be a duplicate :( or I can accept your answer. –  Nov 06 '19 at 21:28