Disable https on localhost - apache

I need to automatically redirect any https:// to http:// on my localhost environment.
I tried to use a .htaccess file which I placed on my htdocs/ with the following code:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
For some reason this is not working. Any advice?

The problem with the rewrite rule is that it will never be reached if apache is not configured properly for SSL. The browser is trying to connect to http://localhost:443 and unless apache or some other service is configured on that port you'll get a timeout.
The best solution would be to create a self-signed certificate for apache running on localhost and create a rule in your web browser to trust the certificate:
Create a self-signed certificate for apache:
http://www.perturb.org/display/entry/754/

Related

Apach redirecting https 443 to https with custom port like 3128

I am using Apache web server in front of Squid proxy server on the same machine, and got SSL certificate from Letsencrypt and Apache server now is trusted green site.
I changed the htaccess file to suit my needs to reach Squid server behined Apache in two cases with https or without it . So my htaccess file as following:
RewriteEngine On
# if not https Redirect all requests to Squid except for Let's Encrypt's ACME Challenge verification
RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/ [NC]
RewriteRule ^(.*) http://backend.squid.server:3128/$1 [R=301,L]
# if https on Redirect all requests to Squid except for Let's Encrypt's ACME Challenge verification
RewriteCond %{HTTPS} on [NC]
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/ [NC]
RewriteRule ^(.*) https://backend.squid.server:3128/$1 [R=301,L]
The first part is redirecting well with no problems and I got the respnse from squid server.
but when we send the same request but with https I got the following error
An error occurred during a connection to backend.squid.server:3128.
SSL received a record that exceeded the maximum permissible length.
Error code: SSL_ERROR_RX_RECORD_TOO_LONG .
what I have on Squid.conf if that may help:
https_port 3128 cert=/etc/letsencrypt/live/mysite.tld/fullchain.pem key=/etc/letsencrypt/live/mysite.tld/privkey.pem
http_port 3128 act-as-origin name=server accel vhost
I think the problem in redirecting from https 443 to https with a custom port.
If anyone has dealt with such an issue Please tell me where is the problem ? what is the right syntax for this in htaccess file

Error while adding redirect (301) rule on Cpanel to force ssl

I am new to server and cpanel. I have successfully purchased and installed ssl certificate on my domain. Now when I try to add redirect (301) for http to HTTPS for all traffic under cpanel its giving error " The is error in Apache rule while processing your request".
Please help
Cpanel official documents says:
If you try to setup a Dedicated SSL redirect using the cPanel steps
, cPanel will fail with an error message.
Its best you write your rewrite rules directly into .htaccess file under your root directory.
See here for inmotion hosting help page
Try this in .htaccess:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Redirection https to https within same Apache

I have a requirement where I have to redirect my hostname to particular application which is again hosted on same Apache. Let's take an example, When I hit on host(https://domain1.example.com), It should internally redirect me to Apache Web Application (https://domain1.example.com/application1) without changing the browser URL.
I am not sure how to achieve SSL to SSL redirection. Thanks in Advance..!!!
This should work. This will redirect all incoming urls that are going to domain1.example.com/ to domain1.example.com/application1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.example.com$
RewriteRule ^$ https://domain1.example.com/application1 [L,R=301]
If without changing browsing URL is your goal then PROXY is your way.
Put following in your apache vhost or global file,
ProxyPass https://domain1.example.com/ https://domain1.example.com/application1
ProxyPassReverse https://domain1.example.com/ https://domain1.example.com/application1
PS shibboleth has nothing to do with this, at least you have not mentioned any case.
EDIT
ProxyPass should come to virtural host not in location
Ideally all the location tag should be out of virtual host

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