krestensb
By:
krestensb

setup apache to show www.domain.dk

July 21, 2017 362 views
Apache Ubuntu 16.04

Hi,
I have a domain dagenssalg.dk and both www.dagenssalg.dk and dagenssalg.dk is sendt to the root of my apache server.

But, www.dagenssalg.dk only sends me to "index of /" where dagenssalg.dk runs the python script there as it's supposed to.

Here is my sites-avaliable/FlaskApp.conf:

<VirtualHost *:80>
ServerName dagenssalg.dk
ServerAlias www.dagenssalg.dk
ServerAdmin krestensb@gmail.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =dagenssalg.dk [OR]
RewriteCond %{SERVER_NAME} =www.dagenssalg.dk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Any help is very much appreciated.

Best regards
Kresten

3 Answers

Hi @krestensb

The configuration that you've pasted is for your HTTP (port 80) site and you can change that to the following:

<VirtualHost *:80>
   ServerName dagenssalg.dk
   ServerAlias www.dagenssalg.dk
   Redirect permanent / https://www.dagenssalg.dk/
</VirtualHost>

And then you need to paste your <VirtualHost *:443> block, since that's the configuration which handles your HTTPS (port 443) site.

Hi, Thanks for answering!

Now I changed it to whats below.

I don't thin I understood you right
Now www.dagenssalg.dk is returning: ERRTOOMANY_REDIRECTS

dagenssalg.dk is showing as usual.

<VirtualHost *:443>
ServerAdmin krestensb@gmail.com
ServerName dagenssalg.dk
ServerAlias www.dagenssalg.dk
Redirect permanent / https://www.dagenssalg.dk/
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =dagenssalg.dk [OR]
RewriteCond %{SERVER_NAME} =www.dagenssalg.dk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

  • @krestensb

    Okay, you misunderstood me.
    You have 2 different configurations. You have one for HTTP (port 80) and one for HTTPS (port 443).
    I need you to show both configurations - originally, before you added any of my code.

    And please use the triple-back-tick to insert code blocks like this in the editor:

    ```
    This is a test with multiple lines of code
      Second line is indented
    And the lines just continue :-)
    ```
    

    Use the preview button before posting in top right of the editor (eye-icon).

    If you are unsure what I'm asking, then just write in Danish.

I never added any .conf for port 443 before I started to implement your code.

Would I need one .conf with two bloks like this?

<VirtualHost *:80>
   ServerName dagenssalg.dk
   ServerAlias www.dagenssalg.dk
   Redirect permanent / https://www.dagenssalg.dk/
</VirtualHost>

<VirtualHost *:443>
   ServerName dagenssalg.dk
   ServerAlias www.dagenssalg.dk
   Redirect permanent / https://www.dagenssalg.dk/
</VirtualHost>
Have another answer? Share your knowledge.