skip to Main Content

I have to following configuration in my .htaccess. The first rule puts https before the URL and the second puts www before the URL, if not set already.

# https redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# www redirect
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

These redirects work perfect for the homepage. However, if you call a subpage, these rules wont work.

domain.xy -> https://www.domain.xy (works, Homepage)
domain.xy/contact -> http://domain.xy/contact (doesnt work)

The weird thing is, the favicon get redirected correctly. Example with the contact page, as seen on
this picture.

How can it be, that my configuration only works for the toplevel, not for any subpage?

2

Answers


  1. Chosen as BEST ANSWER

    The problem was another rule in the .htaccess-File. Our hosting provider automatically generates a .htaccess suiting the Typo3 installation. I had to place my rewrite rule before the following lines:

    # If the file/symlink/directory does not exist => Redirect to index.php.
    # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]
    

    This rules, as far as i understand, redirects any request, which is not a file, directory or symlink back to the index.php. So in my case if i call domain.xy/contact, it redirects back to the index.php.

    Because this rule has the [L] flag at the end, the .htaccess stops processing here. So i moved both my rules above this block and they get called before this block comes to action.


  2. I’d say your RewriteRule is wrong. It should be .* instead of ^:

    # https redirect
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # www redirect
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search