.htaccess to remove the slash and without



  • We need to redirect:

    (1) If the address ends on .html and is / at the end, delete / at the end.

    (2) If the address does not end on .html (the catalogue) and is not / at the end, finish / at the end.

    Found a few similar examples and brought them together. Something's wrong with synthaxis and the brain refuses to lie in the debrie of syntaxis htaccess:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (/|.[a-zа-я]{2,5})$ [NC]
    RewriteCond %{REQUEST_URI} ^(.+)/$
    RewriteRule ^(.+)/$ /$1 [R=301,L]
    

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(/|.[a-zа-я]{2,5})$ [NC]
    RewriteCond %{REQUEST_URI} !(.)/$
    RewriteRule ^(.
    [^/])$ $1/ [L,R=301]

    Say it!



  • Start of file .htaccesscleaning / at the address ending at \.htmlwill be like this:

    RewriteEngine On
    RewriteBase /
    

    RewriteRule ^(..html)/$ $1 [L,R=301,NC]

    And then you' a little ambiguous, so I'll bring all the options.

    Addendum / to any address not end .html without / at the end:

    RewriteCond %{REQUEST_URI} !.html$
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.) $1/ [L,R=301]

    Addendum / to an address not having / at the end, indicating the catalogue:

    RewriteCond %{REQUEST_URI} !/$
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule (.*) $1/ [L,R=301]

    And if you need to add / to any address not ending on .htmlwithout / at the end and pointing to the catalogue, the beginning will change somewhat:

    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.*.html)/$ $1 [L,R=301,NC]

    RewriteCond %{REQUEST_URI} !.html$
    RewriteCond %{REQUEST_URI} !/$
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule (.*) $1/ [L,R=301]


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2