skip to Main Content

I am running 2 websites on the same server:

  • www.example.com example.com – WordPress
  • sub.example.com – another site

Requesting http://sub.example.com should of course respond with the index for that website. Instead it redirects to http://www.example.com unless I explicitly request http://sub.example.com/index.html, in which case I get the correct website.

I think the issue may be WordPress’s .htaccess file for permalinks (generated by WordPress):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Here are my VirtualHost conf files for both sites:

# sub.mysite.com
<VirtualHost *:80>
    DocumentRoot /var/www/sub
    ServerName sub.example.com

    <Directory /var/www/sub/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</Directory>

# www.example.com example.com
<VirtualHost *:80>
    DocumentRoot /var/www/wordpress
    ServerName www.example.com
    ServerAlias example.com

    <Directory /var/www/wordpress/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</Directory>

2

Answers


  1. Chosen as BEST ANSWER

    Turns out it was just my browser caching a permanent redirect from sub to www, which was probably the result of an improper configuration that I fixed before.


  2. Try replacing your server IP after

     <VirtualHost 12.345.56.789:80>
     ServerName sub.example.com
     DocumentRoot "/var/www/sub"
     <Directory /var/www/sub>
         Allow from all
         AllowOverride All
     </Directory> </VirtualHost>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search