Reputation: 7520
I have this command in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
And this command remove the .html at the end this looks ok but how can I add at the end? Because if I try this code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
The .html is there again. I want to replace the .html into a trailing slash. And also I want to do this in 1 HTML file only. So my URL is like this for now.
http://mysamplesite.com/project.html/
Upvotes: 1
Views: 178
Reputation: 41219
You can use this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html [L]
Upvotes: 2
Reputation: 785246
You can use it like this:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+project\.html\s [NC]
RewriteRule ^ http://%{HTTP_HOST}/%{REQUEST_URI}/ [NC,L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Upvotes: 1
Reputation: 7476
Try below rule I am assuming project is the file on which you want to apply trailing slash.
RewriteEngine On
RewriteRule ^project$ project/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([\w-]+)/?$ $1.html [L]
Upvotes: 1