Search code examples
.htaccessseo

I can't redirect htaccess slash 301


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]

Solution

  • 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.