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>
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 want to host a single page Vuejs application that has vue router. I am using apache2 virtual host and I have written the code below for the site.
<VirtualHost *:80>
ServerAdmin example#email.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/dist
<Directory /var/www/example.com/dist/>
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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</VirtualHost>
The root directory of my project is /var/www/mydomain.com. Now, when I try to install let's encrypt ssl certificate using this command: certbot --apache -d example.com -d www.example.com it gives me an error saying:
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.
AH00526: Syntax error on line 22 of /etc/apache2/sites-enabled/example.com.conf:
RewriteBase: only valid in per-directory config files.
I don't know what to do. Can anyone help me?
I changed my code like below and it worked!
<VirtualHost *:80>
ServerAdmin example#email.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/dist
<Directory /var/www/example.com/dist/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</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>
I put the following code inside the <Directory /var/www/example.com/dist/> </Directory> part and it is working fine.
<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 have programmed a website which is : www.shoesbank.org
I've used following code to redirect to https. It works perfectly on desktop. But when i want to use it on mobile. I get error which says" the site can not be reached". When i remove https redirection, it is shown perfectly. I have spent tones of hours googling for it, but i found no thing. I appreciate your help.
httaccess:
RewriteEngine On
RewriteEngine on
RewriteCond %{HTTP_HOST} ^shoesbank.org [NC]
RewriteRule ^(.*)$ https://www.shoesbank.org/$1 [L,R=301,NC]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(support\.)?abc\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
When I config my apache server, I prefer to handle https in the apache config instead of in the .htacces.
<VirtualHost *:80>
ServerName shoesbank.org
ServerAlias www.shoesbank.org
Redirect / https://shoesbank.org
</VirtualHost>
<VirtualHost *:443>
ServerAdmin contact#shoesbank.org
DocumentRoot /var/www/shoesbank.org/public_html/
ServerName shoesbank.org
ServerAlias www.shoesbank.org
SSLEngine on
SSLCertificateFile /etc/ssl/shoesbank.org.crt
SSLCertificateKeyFile /etc/ssl/shoesbank.org.key
SSLCertificateChainFile /etc/ssl/shoesbank.org.ca-bundle
<Directory /var/www/shoesbank.org/public_html/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Hopefully It works.
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 !
I'm using vuejs with mode history enabled, and on the docs I find this Histoy mode docs
but then using Let's Encrypt with certbot I run a command to generate an ssl certificate, but now because of the redirection the following configuration no longer works.
<VirtualHost *:80>
ServerName virtuafest.vir.mx
ServerAdmin webmaster#localhost
DocumentRoot /var/www/virtuafest17/dist
<Directory /var/www/virtuafest17/dist>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =virtuafest.vir.mx
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
How can I solve this without having to create an .htaccess file for the Rewrite conf?
Locate VirtualHost: *:443 in etc/apache2/apache2-le-ssl.conf and add your mod_rewrite there.