0

I am using the code in below to redirect index.html and non-www version of URL to www. It also removes *.html extensions from the files. Now, I would like to add a trailing slash at the end of the files across all directories. Following are the examples of what I want to get:

  • www.mydomain.com.au/contact.html goes to www.mydomain.com.au/contact/
  • www.mydomain.com.au/contact goes to www.mydomain.com.au/contact/
  • www.mydomain.com.au/glass-replacement/Brisbane.html goes to /glass-replacement/Brisbane/

and so forth...

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
RewriteCond %{http_host} ^mydomain.com.au$ [nc]
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [r=301,nc,L]

RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\  [NC]
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]

Thanks for your help in advance

Webnerdoz
  • 155
  • 1
  • 6
  • 15

1 Answers1

0

Try this:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
RewriteCond %{http_host} ^glassnow.com.au$ [nc]
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1 [r=301,nc,L]

RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\  [NC]
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1/ [R=301,L]
moobot
  • 477
  • 1
  • 4
  • 20