1

I want to serve all of my website pages over https, but currently my htaccess only serves the homepage over https.

This is the code I have in my htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !on
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

If you go to the following page it is served still over http: http://www.coerll.utexas.edu/spintx/video/1506

But the homepage is served over https: http://www.coerll.utexas.edu/spintx/

What am I doing wrong?

0

1 Answer 1

1

It sounds like you may have put the directives in the wrong place in your .htaccess file. The HTTP to HTTPS redirect needs to go near the top, before any other rewrites.

The nature of your URLs suggest you are using a front-controller type pattern and rewriting requests to a common script. However, the "homepage" does not need to be rewritten (since mod_dir will issue an internal subrequest for the directory index). If you place the mod_rewrite redirect after the front-controller then all but the homepage will be redirected.

UPDATE: From discussion in comments, there are no other directives in .htaccess and it would seem the website is driven with directives in the main server config (not accessible to the OP). Furthermore, it seems the .htaccess file (located in the /spintx subdirectory) is bypassed entirely for all requests, other than the homepage! Access to the server config is probably required in order to diagnose this further and implement an Apache HTTP to HTTPS redirect.

Implementing the HTTP to HTTPS redirect in the web application itself (Drupal 7) would be an alternative.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

These directives are generally OK for most servers. You don't really need the <IfModule> wrapper, unless you are planning on copying these same directives to multiple servers where mod_rewrite might not be installed.

The RewriteRule pattern ^(.*)$ can be simplified to just ^ since the captured subpattern is not being used in the substitution (you are using the REQUEST_URI server variable instead).

14
  • 1
    That is the only mod_rewrite code in my htaccess file. I don't know if there are other htaccess directives on the server, since I am not maintaining the server. So could this front-controller be somewhere else on the server?
    – nschildre
    Commented Jan 7, 2020 at 19:20
  • The "front-controller" could be in the main server config / virtual host. If it is then you won't be able to change this behaviour in .htaccess. Do you not control these aspects of the website? Where exactly in the .htaccess file located? Do you have other .htaccess files in subdirectories? "other htaccess directives on the server" - they are "Apache directives", .htaccess is just a context in which they can be used.
    – MrWhite
    Commented Jan 7, 2020 at 19:33
  • I don't control the server config/virtual host. My .htaccess file is located in the root folder of my website. I have the mod_rewrite issue with several websites that are hosted on that server, but my htaccess websites do work. In one instance I successfully increased the php_value memory_limit.
    – nschildre
    Commented Jan 7, 2020 at 19:45
  • And where is the "root folder of your website"? Is this in the /spintx subdirectory? How are the URLs being routed?
    – MrWhite
    Commented Jan 7, 2020 at 21:28
  • 1
    Apache 2.2.15. Yes there is no server error for subpages. I did add something at the start of the .htaccess and had again a server error for the homepage and no server error for the subpages. So I guess you are right, the server team here is blocking my .htaccess file for the subpages. I will have to contact them again to see why this is the case. I just wanted to double check that my directive code was correct. But I guess that is the case. Thanks for your help in figuring out this strange issue.
    – nschildre
    Commented Jan 8, 2020 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.