website not showing when using ssl on mobile but shows on desktop - apache

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.

Related

Apache configuration for slim3 with ssl

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>

Vue.js Apache configuration with 301 https redirection (mode history)

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.

Naked domain automaticly redirects but www not

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>

http to http redirect virtual host in apache

Hi im configuring a server in CentOS 6.5 with apache 2.4 and PHP 5.5
I install an SSL certificate and all go fine.
in another server i did the http to https redirect on htaccess file.
i meke test with that in my new server and didnt work, here are my configuration:
My .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/phpmyadmin/.*
RewriteCond %{REQUEST_URI} !/phpMyAdmin/.*
RewriteRule ^ index.php [L]
</IfModule>
My virtual host file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
DocumentRoot /var/www/laravel-project-namel/public
<Directory /var/www/laravel-project-namel/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.crt
SSLCertificateKeyFile /etc/pki/tls/certs/cert-valido-private.key
SSLCertificateChainFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.pem
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
DocumentRoot /var/www/laravel-project-namel/public
<Directory /var/www/laravel-project-namel/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
i replace the domain and the folder to generic names, but all other are true.
(sorry about my english)
i did search and test every solution i found, but my site refuse to redirect.
Problem is you're not capturing the URI in patter and using $1, %1 as back-reference.
Try this rule in your root .htaccess as very first rule:
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

Combining Rewrite Rules - http to https AND all links to one file while maintaining clean URL

Over the past few days, I have read quite a few forums and StackOverflow answers on rewriting URLs in apache.conf and converting http to https using rewrites. Thanks to StackOverflow, I have figured out how to do both separately. Unfortunately, I haven't found a solution that can combine the two while allowing me to keep my clean URL appearance AND while letting me pass a variable to page in a hidden manner.
Here is the current directory part of my apache.conf file:
<Directory /home/tim/example>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sort-url.php?rt=$1
</Directory>
I currently pass of "https://example.com/CA/Los-Angeles" to a file called "sort-url.php", where I get the "rt" variable, explode it into an array using the "/", and then use the variables like $route_array[0] for "CA" and $route_array[1] = "Los-Angeles". Right now, the user will never see "sort-url.php", so my URLs always look clean. I want to keep this same effect, but convert http to https for all sites.
I found this code to convert to https if I substitute this rewrite rule for the other rewrite rule:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}/sort-url.php?rt=$1 [R,L]
But, this causes "sort-url.php?rt=CA/Los-Angeles" to show up in the URL. If I get rid of the "sort-url.php in the rewrite rule like this:
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
It won't know to route all requests to the sort-url.php file, but it will look like the clean link I want with https.
Am I going about it the wrong way? Is it possible to combine the two rules while maintaining a clean URL?
Thank you in advance,
Tim
ADDITION - Here are my virtual hosts:
<VirtualHost XXX.XXX.XX.XXX:12345>
ServerName example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost XXX.XXX.XX.XXX:80>
ServerName example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost XXX.XXX.XX.XXX:443>
ServerName example.com
DocumentRoot /home/tim/example
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.com.crt
SSLCertificateKeyFile /etc/ssl/certs/example.key
SSLCertificateChainFile /etc/ssl/certs/sf_bundle.crt
</VirtualHost>
Enable .htaccess if not already enabled.
Try this code in your DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sort-url.php?rt=$1 [L,QSA]
I suggest suppressing Directory clause (COMMENT), and this in vhosts:
<VirtualHost XXX.XXX.XX.XXX:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /home/tim/example
Redirect / https://example.com/
</VirtualHost>
<VirtualHost XXX.XXX.XX.XXX:443>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /home/tim/example
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.com.crt
SSLCertificateKeyFile /etc/ssl/certs/example.key
SSLCertificateChainFile /etc/ssl/certs/sf_bundle.crt
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ /sort-url.php?rt=$1 [L,QSA]
</VirtualHost>
Ok, it appears my load balancer configuration (SSL termination on LB, port 80, etc.) was throwing me for a loop and "X-Forwarded-Proto" was the answer I needed. Here is my updated directory part:
<Directory /home/tim/example>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=permanent]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sort-url.php?rt=$1 [L,QSA]
</Directory>