Ad

I Can't Redirect Htaccess Slash 301

- 1 answer

when I enter the htaccess code on website.com/seo.php, it redirects to website.com/seo, but I want it to do website.com/seo/

my htaccess codes:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Ad

Answer

Use this instead of the current one:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

What I changed:

RewriteRule ^ %1 [R=301,L] to RewriteRule ^ %1/ [R=301,L] (adding a / after %1)

Don't forget to clear cache.

Ad
source: stackoverflow.com
Ad