The problem I’m having is that the first URL works and the second one doesn’t.
http://www.example.com/podcast/episode1
http://www.example.com/podcast/episode1/
Is there a way to redirect all trailing slash versions to the non-trailing slash version?
The problem is even worse here, since neither of these work:
example.com/podcast
example.com/podcast/
Only this one works:
example.com/podcast.html
and I do not want the html extension visible.
Here’s the code I have in my .htaccess file so far:
#shtml
AddType text/html .html
AddHandler server-parsed .html
#html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://example.com/ [R=301,L]
#non www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Can you help me out?
Removing the trailing slash is easy. Removing the
.htmlisn’t.Removing the slash
Just R=301 redirect if you see a slash on there.
RewriteRule ^(.*)/$ $1 [R=301]Don’t add the
Lflag since you want to continue processing this request. Also make it the first rule.Why you can’t remove the
.htmlYour issue is that once
pagebecomespage.html(via the internal redirect), a new request forpage.htmlis given to the server. So then your .htaccess will see the request forpage.htmland redirect topage. Cue infinite loop.Optimising your code
RewriteEngine Ononce at the top of your.htaccesswwwredirect to the top of your code and remove theLflag (see Removing the Slash)