Why are clean URLs not working when redirecting to https?

1k views Asked by At

I added some lines in my htacess file to redirect all http requests to https. Now when I type in a URL like: http://example.com/frames/view/4701362, it redirects to: https://example.com/index.php?q=frames/view/4701362. I can go to the page manually: https://example.com/frames/view/4701362 and the URL does not get changed.

I have Clean URLs set up

Clean URLs configuration

Htaccess file

<IfModule mod_rewrite.c>
  RewriteEngine on

  #some more stuff here, unrelated 

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

Edit: I tried reversing the Drupal index.php?q= line and the https lines like this...

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

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

But then my site did not load properly and said Page not found even at the homepage.

1

There are 1 answers

1
AllisonC On

Thanks to @MikeRockett above, I was able to figure this out. In addition to his suggestion, I had to add [L,R=301] to the RewriteRule line.

<IfModule mod_rewrite.c>
  RewriteEngine on

  #some more stuff here, unrelated 

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

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

</IfModule>