skip to Main Content

When I enter the website.com/seo link, I want to make a 301 redirect to the website.com/seo/ link. However, I don’t want it to be broken in the codes I wrote in the current htaccess.

my htacces 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]

2

Answers


  1. Use only one of these, do not use together!

    Try:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} !^/(.*?)/$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
    
    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]
    

    If that doesn’t work, use:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/(.*?)/$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [NC,L]
    

    Remove the previous rules, and try once. If it works after removing previous rules, then let me know.

    Login or Signup to reply.
  2. Based on your shown samples, could you please try following. Please clear browser cache before testing your URLs

    RewriteEngine ON
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
    
    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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search