0

I have the same problem as the User in this thread. I basically want to redirect all http requests to https without www using htaccess.

I have implemented a solution to this problem and it does a pretty good job.

However, it does not redirect to the corresponding URI. If I visit my website on port 80 example.com/news I will be redirected to https://example.com/index.php which is basically the root page..

I really need your help guys, I totally have no clue about htaccess..

EDIT This is what my mod_rewrite looks like..

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Dean
  • 301
  • 1
  • 3
  • 13
  • Well, how do you expect us to help without you posting your current code of that dynamic configuration file? – arkascha Jun 04 '17 at 11:56
  • @arkascha I updated my post. – Dean Jun 04 '17 at 12:04
  • The issue _probably_ is that you _first_ rewrite to `index.php` and _then_ make an external redirection. Try changing the order of the rules. Note that the `L` flag only terminates the _current_ walk through the rule set. It is restarted after that. – arkascha Jun 04 '17 at 12:07
  • Moved the `index.php` rewrite to the end. Works perfectly now. Thank you for your help! Please make an answer so I can accept it :) – Dean Jun 04 '17 at 12:10

1 Answers1

0

The issue probably is that you first rewrite to index.php and then make an external redirection. Try changing the order of the rules. Note that the L flag only terminates the current walk through the rule set. It is restarted after that. So first do the external direction to switch to the https protocol, then do the internal rewriting if that is corrected.

arkascha
  • 41,620
  • 7
  • 58
  • 90