Question

setup apache to show www.domain.dk

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:

		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

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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>

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: ERR_TOO_MANY_REDIRECTS

dagenssalg.dk is showing as usual.

                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>```

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.