I've been trying to host 2 websites on my Ubuntu 18.04 server.
The two domains are pointing to the first site (Bilbao-deco).
As you can see on my.conf file, my two document root are different.
I can't tell what I did wrong, I'll be glad if anyone could help !
<VirtualHost *:80>
ServerName bilbao-deco.fr
ServerAlias bilbao-deco.fr
ServerAdmin nicolasalric#hotmail.fr
DocumentRoot /var/www/html
<Directory /var/www/html>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{SERVER_NAME} =bilbao-deco.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerName api.nalric.fr
ServerAlias api.nalric.fr
ServerAdmin nicolasalric
DocumentRoot /var/www/api/www/api_tub_ws/html
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.nalric.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Update : my problem were caused by certbot, it made another conf file, which is not the default one !
Related
I want to redirect my non-www to www .
SSL working fine and both url working fine with ssl.
https://example.com
https://www.example.com
both working but I want to redirect https://example.com to https://www.example.com
I am working with lamp-server in AWS ec2 and using certbot for ssl.
My apache config.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I tried many online tutorials but nothing helped, Thanks in advance for any help or support.
Try (note: Apache may throw errors if the comments starting with # are not removed):
# turns on the rewrite engine
RewriteEngine On
# checks if domain is not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
# redirects to www.example.com
RewriteRule ^ https://www\.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# the above is enough for 443 VirtualHost
# checks if https is not on
RewriteCond %{HTTPS} !on
# redirects to https on the same domain
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
So, your full configuration:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www\.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
Add the following to the <VirtualHost *:443> configuration:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www\.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I'm trying to setup my apache configuration file with my slim framework application to use ssl. I've done this in the past but for whatever reason, I'm getting 404 errors when I try to access any page other than the home page. Here is my apache configuration file:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{SERVER_NAME} =www.my-site.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
ServerAdmin my.email#gmail.com
ServerName www.my-site.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/privkey.pem
ServerAdmin my.email#gmail.com
DocumentRoot /wwwroot/sites/my-site/public
ServerName www.my-site.com
ErrorLog logs/www.my-site.com-error_log
CustomLog logs/www.my-site.com-access_log common
<Directory "/wwwroot/sites/my-site/public">
AllowOverride All
RewriteEngine On
RewriteBase /wwwroot/sites/my-site/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>
</VirtualHost>
As stated, my home page works exactly as I'd expect it to work. But when I try to go to https://www.my-site.com/another/page, I get a 404 error.
I have a dev version of this project set up on another server that doesn't use https and I have no problems going to http://dev.my-site.com/another/page.
try set RewriteBase to /
<Directory "/wwwroot/sites/my-site/public">
AllowOverride All
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>
I'm having trouble deploying a vue application (no database nor server-side code) with Apache (HTTPs too). This is my .conf file:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
ServerName mydomain.me
ServerAlias www.mydomain.me
DocumentRoot /var/www/mydomain.me/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/mydomain.me/dist>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.me [OR]
RewriteCond %{SERVER_NAME} =www.mydomain.me
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
When I access mydomain, the frontpage is correctly loaded (the index.html built with npm run build), however none of the routes work (i.e. /portfolio).
If, however, I switch my router mode from history to hash, things work (/#/portfolio), but I want to keep history mode active.
Thanks in advance!
Ended up with a solution - not sure if it's the best one but it works for my case.
/etc/apache2/sites-enabled/mydomain.me-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mydomain.me
ServerAlias www.mydomain.me
DocumentRoot /var/www/mydomain.me/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/mydomain.me/dist>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.me [OR]
RewriteCond %{SERVER_NAME} =www.mydomain.me
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mydomain.me/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.me/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
.htaccess on /var/www/mydomain.me/dist
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [QSA,L]
</IfModule>
Your case is tricky because those RewriteConds and RewriteRule you have seem to be redirecting to HTTPS.
If that's so, here's something that might work:
/etc/apache2/sites-enabled/mydomain.me-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mydomain.me
ServerAlias www.mydomain.me
DocumentRoot /var/www/mydomain.me/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/mydomain.me/dist>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.me [OR]
RewriteCond %{SERVER_NAME} =www.mydomain.me
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mydomain.me/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.me/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
.htaccess on /var/www/mydomain.me/dist
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
I want to redirect my traffic to HTTPS
Coming from myawesomesite.com it redirects to https://myawesomesite.com, and coming from http(s)://www.myawesomesite.com it goes to HTTP or HTTPS based on the call.
What's wrong?
My virtualhost file is:
<VirtualHost *:80>
DocumentRoot /var/www/myawesomesite/public
ServerName myawesomesite.com
ServerAlias www.myawesomesite.com
<Directory "/var/www/myawesomesite/public/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/myawesomesite-error_log
RewriteEngine On
RewriteCond %{SERVER_NAME} ="myawesomesite.com" [OR]
RewriteCond %{SERVER_NAME} ="www.myawesomesite.com"
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>
This is the correct way to force SSL via Rewrite functions:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
Of course, remove your current code. Enjoy!
Update:
You can also do this which is better:
<virtualhost *:80="">
ServerName www.example.com
Redirect / https://www.example.com/
</virtualhost>
I need to redirect all http requests to https except /sports-scores, /sport-scores/, and sport-scores.html pages.
I've been at it for two hours. My brain is fried and I can't make sense any sense from this.
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www
ServerName www.my-domain.com
ServerAlias my-domain.com
DirectoryIndex index.php index.html
RewriteEngine on
CustomLog /var/log/apache2/www.log combined
ErrorLog /var/log/apache2/errors-www.log
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost 127.0.0.1:443>
DocumentRoot /var/www
ServerName www.my-domain.com
ServerAlias my-domain.com
DirectoryIndex index.php index.html
SSLEngine on
SSLCertificateFile /home/user/gandi-ssl/www.crt
SSLCertificateKeyFile /home/user/gandi-ssl/server.key
SSLCertificateChainFile /home/user/gandi-ssl/www.crt
CustomLog /var/log/apache2/www.log combined
ErrorLog /var/log/apache2/errors-www.log
RewriteEngine On
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>
I need to redirect all http requests to https except /sports-scores,
/sport-scores/, and sport-scores.html pages.
You need to adjust your 80 Virtual Host config and use the below rewrite rule.
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www
ServerName www.my-domain.com
ServerAlias my-domain.com
DirectoryIndex index.php index.html
CustomLog /var/log/apache2/www.log combined
ErrorLog /var/log/apache2/errors-www.log
RewriteEngine On
RewriteCond %{HTTPS} !^on
RewriteCond %{REQUEST_URI} !^/sports-scores
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost 127.0.0.1:443>
DocumentRoot /var/www
ServerName www.my-domain.com
ServerAlias my-domain.com
DirectoryIndex index.php index.html
SSLEngine on
SSLCertificateFile /home/user/gandi-ssl/www.crt
SSLCertificateKeyFile /home/user/gandi-ssl/server.key
SSLCertificateChainFile /home/user/gandi-ssl/www.crt
CustomLog /var/log/apache2/www.log combined
ErrorLog /var/log/apache2/errors-www.log
RewriteEngine On
RewriteCond %{HTTPS} ^on
RewriteCond %{REQUEST_URI} ^/sports-scores
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
Let me know how this works out.