0

I was wondering if someone could lend a hand with a small .htaccess issue.

Inside the .htaccess file is this for example:

Options -Indexes 
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

# Normal
RewriteRule ^about$ ./about.html [L,NC]
RewriteRule ^news$ ./news.html [L,NC]
RewriteRule ^other$ ./other.html [L,NC]

This works great if you want to enforce HTTPS and NOT have a forward slash after domain.com/about

My question is:

How do I enforce HTTPS and add the forward slash at the end like so;

https://www.domain.com/about/

or allow a user to add the forward slash at the end without it redirecting them to a 404 error page.

Also they are just HTML pages inside the main folder on the server.

Once apon a time, you would have to create folders "about" , "news", "others" etc and place an index.html file in each with all the images, css and js etc just to get the forward slash.

I hope this can be done.

Thanks!

Ryan
  • 1
  • 1

1 Answers1

0

You need to add a rule to enforce the slash then change your existing rewrites so that they match against it:

Options -Indexes -Multiviews
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

# enforce the trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+[^/])$ /$1/ [R,L] 

# Normal
RewriteRule ^about/$ ./about.html [L,NC]
RewriteRule ^news/$ ./news.html [L,NC]
RewriteRule ^other/$ ./other.html [L,NC]

Also, to be on the safe side, turn off Multiviews.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I would also try `^(.*)([^/])$` for the trailing slash rule to allow subdirectory paths. See http://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end – Stuart Wagner Apr 29 '15 at 18:53
  • Hello I did try that however when making changes to the "Normal" section by adding a / after each rule example: about/$. When looking at the website, it seems that when you go to any link, it just goes to www.domain.com// with a double forward slash. – Ryan May 01 '15 at 15:25
  • I mean, if it is possible to allow users to add a forward slash that would be fine too, however at the moment when and if a user was to go to domain.com/about it would work just fine, but if they were to add the forward slash like, domain.com/about/ it would redirect them to the 404 error page. – Ryan May 01 '15 at 15:28
  • @Ryan sorry, that `%1` should have been a `$1` – Jon Lin May 01 '15 at 16:01
  • @JonLin Thanks for your help but the changes still are not giving the results we are hoping for. Still being sent to the 404 error one some of the pages, however on the ones that do load they do not load correctly, they load no css nor js, just plain html text it would seem, very odd. – Ryan May 01 '15 at 21:46