CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Apache configuration (http://www.codingforums.com/forumdisplay.php?f=69)
-   -   Help with adding trailing slash to URL (.htaccess) (http://www.codingforums.com/showthread.php?t=278799)

MBI 10-22-2012 11:58 PM

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]

stevenmw 10-27-2012 04:14 PM

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

MBI 10-30-2012 06:01 AM

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:

Quote:

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


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


All times are GMT +1. The time now is 07:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.