Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    MBI
    MBI is offline
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help with adding trailing slash to URL (.htaccess)

    So I have been able to hide the .html extension on my pages, but I can't seem to get the trailing slash working. I've tried multiple codes with no luck. Here is how I configured my .html extension removal in .htaccess:

    #force www
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    # remove .html ONLY if requested directly
    RewriteCond %{THE_REQUEST} (\.html\sHTTP/1)
    RewriteRule ^(.+)\.html$ /$1 [R=301,L,QSA]

    # remove trailing slash ONLY if it is not an existing folder
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # rewrite to FILENAME.html if such file does exist and is not a folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ /$1.html [L,QSA]

  • #2
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    Code:
     
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php
    replace .php with the extension you want to hide

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ http://www.example.com/yourdirectory/$1/ [R=301,L]
    add trailing slash
    you will need to reference your target directory for this to work properly

  • #3
    MBI
    MBI is offline
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I tried using the above codes, No change happened... Most of my website is in the same root directory, except for my blog so for the last line of your code I just tried:

    RewriteRule (.*)$ http://www.example.com/$1/ [R=301,L]


    What am I missing? I also changed the .php to .html like you said


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •