1

I installed an ssl certificate on my site, when i enter a url with "https", it loads the way it should, but when i enter a url with only "http" like "http://example.org/menu" it redirects me to "https://example.org/index.html" and i dont know why. This is what my htaccess contains

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^imgs$ imgs [NC,L,QSA] RewriteRule ^static$ static [NC,L,QSA] RewriteRule ^test$ index.html [NC,L,QSA] RewriteRule ^login$ index.html [NC,L,QSA] RewriteRule ^menu$ index.html [NC,L,QSA] RewriteCond %{HTTPS} on! RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

All rules say index.html because it is an SPA, before i install de ssl and add the two latest lines it worked with no problem, but now every url that i enter with http redirects to "https://example.org/index.html"

1 Answer 1

1

The problem is the redirect is happening after you've rewritten the URL. Your redirects need to be before your rewrites. Also, the first two conditions are only being applied to the first rule, they're not globally applied. You probably want something along the lines of this:

Options +FollowSymLinks -MultiViews RewriteEngine On # Redirect first, then apply any rewrites after the browser loads the new URL RewriteCond %{HTTPS} on! RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # If any request is for an existing resource, stop the rewriting immediately RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^imgs$ imgs [NC,L,QSA] RewriteRule ^static$ static [NC,L,QSA] RewriteRule ^test$ index.html [NC,L,QSA] RewriteRule ^login$ index.html [NC,L,QSA] RewriteRule ^menu$ index.html [NC,L,QSA] 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, bro. It works but i had to delete the line "RewriteRule ^ - [L]" with that line all my urls were not found, thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.