HTTPS 301 while on CloudFlare w/ Flexible SSL (Apache) - apache

I am trying to have all variations of my root domain 301 (properly) to the https:// version while using CloudFlare w/ Flexible SSL enabled and hosted on an Apache webserver.
My goal is for the following versions to always 301 to https:// domain.tld version ...
http:// domain.tld
http:// www.domain.tld
https:// www.domain.tld
Here is the current code I have...
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [NC]
RewriteRule ^ https://domain.tld%{REQUEST_URI} [R=301,L]
Here is the documentation CloudFlare provides for those on "Flexible SSL"; can someone please assist me with this? It will be useful for almost every domain I have w/ CloudFlare enabled. Thanks!

Why aren't you just trying to use the Always Use Https:// option found in your CloudFlare PageRule settings?

Related

HTTPS redirection on AWS ELB

We have web servers running Apache behind an AWS ELB. I have setup the ELB to accept HTTPS connections, and send the requests over HTTP to the webservers. This works fine.
I have also redirected all the requests to ELB from HTTP to HTTPS using HTTP:X-Forwarded-Proto.
I have added the below virtualhost section to my httpd.conf file and restarted Apache. This setup is redirecting HTTP requests to HTTPS but it is landing on the Apache home page instead of the expected site.
ServerName www.myexample.com
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/index.html https://%{SERVER_NAME}/%{REQUEST_URI} [R=301,L]
The configuration seems to be simple and straightforward but not working.
Please let me know what is wrong in the above setup and why is it landing on the Apache home page.
You should escape the . in your rewrite rule. Change your Rewrite to be:
RewriteRule "!/index\.html" https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also, as in the comment to your OP Remove the slash between %{HTTP_HOST}%{REQUEST_URI}

Redirect non https domains to http

I have around 6-7 DOMAINS hosted on linode server where apache is a webserver. One domain is ssl configured and other runs on http only.
Suppose https://www.example.com is ssl configured .
others are
http://www.example1.com
http://www.example2.com
http://www.example3.com
http://www.example4.com
What would be the dynamic rule if someone put https://www.example1.com or others get redirect to http://www.example1.com and so on
like in virtalhost setting for https something like
<If "%{HTTP_HOST} != 'example.com'">
Redirect permanent / http://%{HTTP_HOST}/
</If>
above written hack doesn't work . any help?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example1\.com$ [NC]
RewriteRule ^ http://www.example1.com%{REQUEST_URI} [NE,R=301,L]

Redirect subdomain to parameter without wildcard SSL certificate

I'm trying to do which might be not possible at all.
Let's say I own mydomain.com and have standard (no wildcard) RapidSSL certificate which works for www.mydomain.com and mydomain.com.
I'd like to redirect (.htaccess) subdomain.mydomain.com to mydomain.com/?param=subdomain.
I already managed to redirect it to subdomain.mydomain.com/?param=subdomain but the problem is that on every redirection I get browser warning concerning my certificate which doesn't cover any subdomain.
Is it possible to redirect it without the warning? I need subdomain only for pretty passing the parameter and I don't need it after redirection.
I think you want to capture the subdomain in the URL as shown in the 2nd RewriteCond and then use it as the parameter value:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.mydomain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mydomain.com [NC]
RewriteRule (.*)?param=%2/$1 [L]
</IfModule>
This is a link to the above solution... http://www.mediacollege.com/internet/server/apache/mod-rewrite/subdomains.html
Hope this helps!
... (no wildcard) RapidSSL certificate which works for www.example.com and example.com .... like to redirect (.htaccess) subdomain.example.com to example.com/?param=subdomain
This is not possible, at least not without warnings about invalid certificates.
The redirection is done within HTTP. But with HTTPS the HTTP layer is embedded inside a SSL layer so that you first have to successfully establish the SSL connection before you can redirect. But to successfully establish the SSL connection you have to have a valid certificate for subdomain.example.com, which you don't have.

Rewrite from https to http

I have 5 sites on one apache server. One of the sites is with SSL. So when the other sites are accessed with https then they are redirected to the SSL site which is incorrect.
E.g.
https://x.com (with SSL)
http://y.com (normal site no SSL)
If I access https://y.com then I get the content from x.com. How can I fix so https://y.com just gets rewritten to http://y.com?
In your .htaccess put:
RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://y.com/$1 [R=301,L]
You can define it in apache config file. You must add a rule to connection incoming from https port.
If you are using linux, propably you have this config in /etc/apache2/sites-available/default-ssl.
If you don't have this file you must searching https virtualhost:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>

Apache mod_rewrite to merge two domains to one SSL connection

I've got a client who recently changed their name. They had an SSL certificate for their site, and I was using mod_rewrite to ensure all requests to domain1.com and www.domain1.com went to https://domain1.com.
Now that they are domain2.com, I'd like everything to go to https://domain2.com. Not so easy, it turns out. I have everything working right except for requests to https://domain1.com. That doesn't get rewritten and it trips the domain mismatch error for the SSL cert.
Here's my rewrite rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain2\.com$ [NC]
RewriteRule .? https://domain2.com%{REQUEST_URI} [R=301,L]
Any advice you could provide would be greatly appreciated!
Aaron.
You need a SSL certificate including domain1.com and domain2.com (costs more).