1

So I have the following problem: When I use https://www.example.com as the domain, I get the content but when I use https://example.com I get the generic TYPO3 404 error page.

I tried setting up a redirect with example.com and .* as the source path and my starting page as the target and I also tried setting up baseVariants in the site config. It's a bit strange that my normal base is just example.com and not www.example.com but www.example.com is the one that is working while the other one just gives a 404.

I need to reliable have https://example.com and https://example.com configured to get the same page.

I use TYPO v12.4.14 on an Ubuntu 22.04.4 with an Apache Webserver and PHP 8.1

[This is what I tried with the redirects. But that does not work because the regular expression has no delimiters. At least that is what I learned in the time since I made this post initially] 1

Edit 2: I tried to make 2 vhosts to redirect example.com to www.example.com. Here are my config files:

File 1 example.conf:

<VirtualHost *:80>

    ServerName example.com
    ServerAdmin [email protected]
    Redirect permanent / https://www.example.com

</VirtualHost>

File 2 example-ssl.conf

<VirtualHost *:443>

    ServerName example.com
    ServerAdmin [email protected]
    Redirect permanent / https://www.example.com

</VirtualHost>

Now it works for http:// example. com but not for https:// example. com

Note: I asked this before on stack overflow, and copyed it to here.

This is my default conf 000-default-le-ssl.config

<IfModule mod_ssl.c>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    # ServerName example.com

    ServerAdmin [email protected]
    DocumentRoot "/var/www/Example/public/"

    <Directory "/var/www/Example/public">
         Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Order allow,deny
     allow from all
    </Directory>


    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf



Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    Redirect permanent / https://www.example.com/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf


</VirtualHost>

1 Answer 1

0

Remove the Redirect permanent / https://www.example.com directive from your File 2 (example-ssl.conf) and add a rule to force www. in your URI.

Your example-ssl.conf configuration should look like this:

<VirtualHost *:443>

    ServerName example.com
    ServerAdmin [email protected]
    
    # Force www in URI 
    <IfModule mod_rewrite.c>
        RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
        RewriteCond %{HTTP_HOST} !^www\. [NC]
        RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>

</VirtualHost>

The RewriteCondition checks if the host is your domain and without www. If so, then it redirects to www.example.com. Because this is server side, your 404 error should disappear.

EDIT: If the rewriting in the VHost does not work, then you can also move it to the .htaccess file in the Docroot. The TYPO3 Default htaccess comes with a rewrite section. Must be located in line 300 round about. Should then look like this:

......

### Begin: Rewriting and Access ###

# You need rewriting, if you use a URL-Rewriting extension (RealURL, CoolUri).

<IfModule mod_rewrite.c>

    # Enable URL rewriting
    RewriteEngine On
    
    # Non www to www
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule ^(.*) https://www.example.com/$1 [L,R=301]

......
13
  • This does not work for me. I also tried adding this to the default ssl conf and that also does not work and gives me the typo 404 site config not found error.
    – sKling
    Commented Apr 22 at 10:19
  • You now need the site config for www.example.com
    – Mogens
    Commented Apr 22 at 10:21
  • And your Server needs the mod_rewrite modul. You can check this in the php info.
    – Mogens
    Commented Apr 22 at 10:22
  • Please first check if the rewriting works. If you type https://example.com in the browser, does it rewrite the URL to https://www.example.com?
    – Mogens
    Commented Apr 22 at 10:24
  • No the rewrite does not work. @Mogens
    – sKling
    Commented Apr 22 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .