-1

First of all, I'm new to stackoverflow, so sorry if the title should've been more descriptive.

I've searched and tried different solutions posted here on stackoverflow but not a single one seems to solve my specific issue.

First of all, here's my .htaccess file

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^website\.io [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.website.io/$1 [R,L]

RewriteRule    ^hosting/?$    hosting.php    [NC,L]
RewriteRule    ^premium/?$    premium.php    [NC,L]
RewriteRule    ^register/?$    register.php    [NC,L]
RewriteRule    ^auth/?$    login.php    [NC,L]
RewriteRule    ^contact/?$    contact.php    [NC,L]
RewriteRule    ^auth/forgot?$    forgot.php    [NC,L]
RewriteRule    ^about/?$    about.php    [NC,L]
RewriteRule    ^auth/activate?$    activate.php    [NC,L]
RewriteRule    ^website/new?$    createwebsite.php    [NC,L]
RewriteRule    ^profile/edit?$    editprofile.php    [NC,L]
RewriteRule    ^auth/logout?$    logout.php    [NC,L]
RewriteRule    ^privacy/?$    privacy.php    [NC,L]
RewriteRule    ^profile/?$    profile.php    [NC,L]
RewriteRule    ^auth/forgot/reset?$    resetPassword.php    [NC,L]
RewriteRule    ^tos/?$    tos.php    [NC,L]
RewriteRule    ^website/?$    websites.php    [NC,L]
RewriteRule    ^website/manage?$    managewebsite.php    [NC,L]
RewriteRule    ^website/manage/([A-Za-z0-9-]+)/?$    managewebsite.php?id=$1    [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^(.*)$ https://www.website.io%1 [R,L,NC]

My first problem is that HTTPS is not being redirected properly in some cases. For example, if I enter "website[dot]io" in the address bar, it redirects to "[https]://www.website.io", the desired result. However, if I type either "[http]://website.io" or "[http]://www.website.io" or "www.website[dot]io" it stays in the HTTP, which I don't want it to. Is there a way to ALWAYS redirect the traffic to HTTPS, regardless of the way it's typed in the address bar?

My second problem is that I want to eliminate the last trailing slash from the url in case someone decides to type it that way. Example "[https]://www.site.io/register/" should redirect to "[https]://www.site.io/register" without the last trailing slash.

Thank you so much, everyone!

P.S.: I replaced some "http(s)" with "[http(s)]" because it won't let me post links.

1 Answers1

0

To remove the trailing slash use: (un tested, from : Htaccess: add/remove trailing slash from URL

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

To Force HTTPS use: (What i use and works with any domains)

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NC,QSA]

As for the value inside the [bracket], it can change depending on you configuration or needs.

Community
  • 1
  • 1
Louis Loudog Trottier
  • 1,367
  • 13
  • 26
  • Just like that, I personnaly found some unexpected behavior when someone tries to access a path that actually exist. Example: if you have a folder called phpClass and someone tries to access example.com/phpClass my code was giving 403 because des directory exist but no index in it. Not sure how( been a while) but i fixed it by ADDING the trailing slash to every request. – Louis Loudog Trottier Feb 05 '17 at 21:02