# [solved] website redirections problem

## Elleni

How can I prevent my webserver to show anything at requests other than mydomain.com and www.mydomain.com. 

Requests to whatever.mydomain.com should not show anything but an error or something. 

I have successfully setup apache and drupal and created a simple site on mydomain.com. I also have setup ssl certificates and successfully setup that http is redirected to https and mydomain.com is redirected to www.mydomain.com. The problem is, if I put whatever.mydomain.com in the browser, I see: 

```
Index of /

Name                    Last modified                 Size  Description

[DIR] drupal/                 2017-05-28 17:13    -   

[DIR] fcgid-bin/              2017-05-28 17:13    -   

Apache Server at whatever.mydomain.com Port 80
```

And when dlicking to drupal I see my website on the following url http://www.whatever.mydomain.com/drupal/ but the links on website do not work with error not found. 

I realize that the page shown is 

```
/var/www/drupal/htdocs/ 
```

 on the server filesystem, and document root would be 

```
/var/www/drupal/htdocs/drupal 
```

The /var/www/drupal folder is a symlink to /var/www/localhost. 

Can you help me sort this misconfiguration out?

Following the files I have created in the folder /etc/apache/vhost.d: 

04_www.mydomain.com.conf: 

```
## Another Virtual hosts statemes ending in </VirtualHost> ###

<VirtualHost *:80>

         ServerName www.mydomain.com

         DocumentRoot "/var/www/drupal/htdocs/drupal"

                         <Directory "/var/www/drupal">

                Options Indexes FollowSymLinks ExecCGI MultiViews

         # AllowOverride controls what directives may be placed in .htaccess files.       

                        AllowOverride All

        # Controls who can get stuff from this server file

#                       Order allow,deny

#                       Allow from all

                        Require all granted

         </Directory>

         <IfModule mpm_peruser_module>

                 ServerEnvironment apache apache

         </IfModule>

#Redirect to SSL

          RewriteEngine On

          RewriteCond %{HTTPS} !on

          RewriteRule ^/(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R]

</VirtualHost>

SSLStaplingCache shmcb:/tmp/stapling_cache(128000)

<VirtualHost *:443>

                ServerName www.mydomain.com

    DocumentRoot "/var/www/drupal/htdocs/drupal"

                ErrorLog /var/log/apache2/drupal.mydomain.com-ssl_error_log

                <IfModule log_config_module>

                                TransferLog /var/log/apache2/drupal.mydomain.com-ssl_access_log

                </IfModule>

                SSLEngine on

                SSLCipherSuite "EECDH+AESGCM EDH+AESGCM EECDH -RC4 EDH -CAMELLIA -SEED !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4" 

                SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/fullchain.pem

                SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem

                SSLUseStapling on

                Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

                <Directory "/var/www/drupal">

                                Options Indexes FollowSymLinks ExecCGI MultiViews Includes

                                AllowOverride All

#                               Order allow,deny

#                               Allow from all

                                Require all granted

                </Directory>

                <FilesMatch "\.(cgi|shtml|phtml|php)$">

                                SSLOptions +StdEnvVars

                </FilesMatch>

                <Directory "/var/www/drupal">

                                SSLOptions +StdEnvVars

                </Directory>

                <IfModule setenvif_module>

                                BrowserMatch ".*MSIE.*" \

                                                nokeepalive ssl-unclean-shutdown \

                                                downgrade-1.0 force-response-1.0

                </IfModule>

                <IfModule log_config_module>

                                CustomLog /var/log/apache2/ssl_request_log \

                                                "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

                </IfModule>

</VirtualHost>

```

05_mydomain.com.conf: 

```
## Another Virtual hosts statemes ending in </VirtualHost> ###

<VirtualHost *:80>

         ServerName mydomain.com

         DocumentRoot "/var/www/drupal/htdocs/drupal"

                         <Directory "/var/www/drupal">

                Options Indexes FollowSymLinks ExecCGI MultiViews

         # AllowOverride controls what directives may be placed in .htaccess files.       

                        AllowOverride All

        # Controls who can get stuff from this server file

#                       Order allow,deny

#                       Allow from all

                        Require all granted

         </Directory>

         <IfModule mpm_peruser_module>

                 ServerEnvironment apache apache

         </IfModule>

#Redirect to SSL

          RewriteEngine On

#         RewriteCond %{HTTPS} !on

#         RewriteRule ^/(.*) https://%{SERVER_NAME}%{REQUEST_URI} [R]

          RewriteCond %{HTTPS} on

          RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]

          RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

</VirtualHost>

SSLStaplingCache shmcb:/tmp/stapling_cache(128000)

<VirtualHost *:443>

                ServerName mydomain.com

    DocumentRoot "/var/www/drupal/htdocs/drupal"

                ErrorLog /var/log/apache2/drupal.mydomain.com-ssl_error_log

                <IfModule log_config_module>

                                TransferLog /var/log/apache2/drupal.mydomain.com-ssl_access_log

                </IfModule>

                SSLEngine on

                SSLCipherSuite "EECDH+AESGCM EDH+AESGCM EECDH -RC4 EDH -CAMELLIA -SEED !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4" 

                SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/fullchain.pem

                SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem

                SSLUseStapling on

                Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

                <Directory "/var/www/drupal">

                                Options Indexes FollowSymLinks ExecCGI MultiViews Includes

                                AllowOverride All

#                               Order allow,deny

#                               Allow from all

                                Require all granted

                </Directory>

                <FilesMatch "\.(cgi|shtml|phtml|php)$">

                                SSLOptions +StdEnvVars

                </FilesMatch>

                <Directory "/var/www/drupal">

                                SSLOptions +StdEnvVars

                </Directory>

                <IfModule setenvif_module>

                                BrowserMatch ".*MSIE.*" \

                                                nokeepalive ssl-unclean-shutdown \

                                                downgrade-1.0 force-response-1.0

                </IfModule>

                <IfModule log_config_module>

                                CustomLog /var/log/apache2/ssl_request_log \

                                                "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

                </IfModule>

</VirtualHost>

```

Thanks in advance for helping me understand where the error is, and how to correct it.  :Smile: Last edited by Elleni on Mon Jun 05, 2017 9:38 pm; edited 1 time in total

----------

## Elleni

I dont even understand if this is a drupal thing or is apache misconfigured ?

----------

## Elleni

It's a pitty no one could help on this one, after further reading I decided to remove the wildcard A record *.mydomain.com and instead making A records for every sub.mydomain.com entries I need.

----------

