0

I set up a testserver for our main website www.example.com.
I set the apache-sites-config to www2.example.com.
I deleted the .htaccess / adjusted it to hold the basic wordpress-entries.
I disabled the autocompletion of the browser.

When I enter www2.example.com I get redirected with moved permanently to www.www2.example.com.

When I enter 192.168.0.1 I get redirected to www.www2.example.com.

Could somebody tell where the error might be?

.htaccess:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

sites-config for the first vHost:

<VirtualHost *:80>
     Protocols h2 http/1.1
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/
     ServerName www2.example.de
     ServerAlias www2.example.de

     <Directory /var/www/html>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

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


<VirtualHost *:443>
        ServerAdmin [email protected]
        Protocols h2 h2c http/1.1
        DocumentRoot /var/www/html/
        ServerName www2.example.de
        ServerAlias www2.example.de

        # added 01.04.2019 BEGINN
        <Directory /var/www/html>
                Options -Indexes +FollowSymLinks
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>
        # added 01.04.2019 END
        <Directory /var/www/html/>
          Options -Indexes +FollowSymlinks
          AllowOverride All
          Require all granted
         allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine off
</VirtualHost>
</IfModule>

sites-config for second vHost

<VirtualHost *:80>
     Protocols h2 http/1.1
     ServerAdmin [email protected]
     DocumentRoot /var/www/html1/example2/
     ServerName www2.example2.eu
     ServerAlias www2.example2.eu

     <Directory /var/www/html1/example2>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

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

The request- and response-header for www2.example.de

Connection:     Keep-Alive
Content-Length: 236
Content-Type:   text/html; charset=iso-8859-1
Date:           Wed, 26 May 2021 10:41:46 GMT
Expires:        Wed, 26 May 2021 10:42:46 GMT
Keep-Alive:     timeout=5, max=100
Location:       https://www.www2.example.de/
Server:         Apache


Accept:         text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:de,en-US;q=0.7,en;q=0.3
Cache-Control:  no-cache
Connection:     keep-alive
DNT:            1
Host:           www2.example.de
Pragma:         no-cache
Upgrade-Insecure-Requests:  1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0
7
  • There's nothing in what you've posted that would trigger such a redirect (there are no redirects in the code you posted). If you enter 192.168.0.1 (the IP address) then the vHost you've posted wouldn't necessarily be called, unless this is the first vHost defined? Aside: You have duplicated some directives and mixing old Apache 2.2 and 2.4 authorisation directives.
    – MrWhite
    May 26, 2021 at 9:09
  • So what else could cause such a redirect?
    – Zehke
    May 26, 2021 at 9:13
  • its one of two vHosts and it resides in the main location for websites
    – Zehke
    May 26, 2021 at 9:39
  • Which vHost is defined first? Add the other to your question. The other vHost might be triggered when typing the IP address.
    – MrWhite
    May 26, 2021 at 9:40
  • Does www.www2.example.com resolve? You are referring to www2.example.com in the question text, but your vHost definitions do not use this ServerName - please clarify. Check the HTTP response headers of the redirect - make sure it's not a cached redirect and check if there is a clue as to what is triggering the redirect... is it WordPress? (WP adds a header if it is.)
    – MrWhite
    May 26, 2021 at 10:03

2 Answers 2

0

You should check WordPress Site URL setting. WordPress sends back a 301 redirect to the site URL if the site URL does not match current virtual host hostname.

0

The SNI was sending the requests to the Live-Server instead of the test-server. And the Live-Server has rewrite-rules.

3
  • SNI? Don't you mean DNS (or perhaps HOSTS file)? Although this wouldn't explain why the local IP address was also being redirected?
    – MrWhite
    May 27, 2021 at 9:11
  • No I mean SNI. Unfortunately I have no access to the SNI so I cannot tell which setting was wrong.
    – Zehke
    Jun 14, 2021 at 6:58
  • But the SNI (part of the security cert) can't "send the request" anywhere?! Something else must be doing that. (?)
    – MrWhite
    Jun 14, 2021 at 10:02

You must log in to answer this question.

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