OK so i'm having a bit of trouble with .htaccess.
I'm using Codeigniter and have just installed a SSL certificate. It's working great except I don't get the blue bar in Firefox, it says 'Your connection to this site is only partially encrypted'
Here's my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (signin)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(signin)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I only want to force SSL on some pages, to start with the signin page (mydomain.com/signin). It seems to remove the index.php/ in the URL fine and it does seem to be forcing the SSL for that page but there's no blue bar :(
I also changed my base_url to the following in the config file to allow http and https:
$config['base_url'] = $config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Any help is most appreciated :)
I think the error is caused by having elements in your page which are downloaded using HTTP instead of HTTPS.
You need to make sure that you either reference all the elements in the page with relative URLs or absolute URLs with the proper protocol (HTTPS instead of HTTP).
Related
I have the following problem
I need two things:
Redirect from unsafe HTTP to safe HTTPS and then
Redirect from https://example.com/index.html to https://example.com/work-for-us
I know the first one I can obtain using:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
and the second one using
RewriteEngine on
RewriteRule work-for-us index.html
But is it possible to connect those two together?
So I have both HTTP -> HTTPS and /index.html -> /work-for-us
I don't have too much knowledge about .htaccess file, I read something on the internet but didn't find anything that answers my question.
So putting everything together, I want to change the URL from this:
http://example.com/index.html to this https://example.com/work-for-us
Thank you in advance.
Based on your shown samples, could you please try following.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine on
##First rule for applying https to URLs.
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
##Second rule for serving homepage(only dns link) with index.html file.
RewriteRule ^/?$ work-for-us [R=301]
RewriteRule ^/?$ index.html [L]
##Third rule for serving non-existing directories/files with index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
Been looking all over for an answer but no response found could solve my problem.
I'm using the following .htaccess file to redirect users from a site to its https version :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
# RewriteCond %{REQUEST_URI} !^/api-vop/
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have first a rule to redirect to HTTPS then a rewrite rule for classic url rewriting to replace urls like myfile.php to /my-file
Thing is I need to let one url which is http://my-server.com/api-vop go through without being redirected to https, as seen by this line :
# RewriteCond %{REQUEST_URI} !^/api-vop/
Thing is I cannot get it to work, at best I'm trhown back to the index.php page.
Any solution anyone ?
Thanks in advance !
Keep your first rule as:
RewriteCond %{HTTPS} off
# This checks to make sure the connection is not already HTTPS
# RewriteCond %{THE_REQUEST} !\s/+api-vop/
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L,NE]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1
I am trying to make test env for this website. I have the same website on live and it is working.
I am trying to redirect the request to do the redirect to this usbfolder(OPS).
This is what I wrote so far but it sounds it is redirecting to root.
If I remove the https it works but with https it doesn't. It sounds it's redirected to root
RewriteEngine on
RewriteBase /OPS/
RewriteCond %{HTTP_HOST} ^dev.domain\.co\.uk$
RewriteCond %{REQUEST_URI} !^/OPS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /OPS/$1 [L]
RewriteCond %{HTTP_HOST} ^dev.domain\.co\.uk$
RewriteRule ^(/)?$ /OPS/index.php [L]
Thank you all for your concern. As #anubhava mentioned the problem was with my document root. We revert back the htaccess to what ever it was. and overwrite the DOCUMENT_ROOT in top of the page and it is working:
if (strpos($_SERVER['DOCUMENT_ROOT'], '/var/www/websites/dev') !== false) {
// OPS(sub-folder)
$_SERVER['DOCUMENT_ROOT'] .= '/OPS';
}
I would like to over-write document root in htaccess if it would have been possible. any way this is the answer I came up with so far.
I've set up wildcard domains locally for testing on .dev
I'm trying to rewrite the following URL:
http://location.domain.dev/
to
http://www.domain.dev/site/location
I would like any requests with www in the subdomain to always go to www.domain.dev but if any request is made to location.domain.dev, I would like to keep that request in the address bar (i.e i dont want people to see the underlying change)
I currently have the following in my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.dev
RewriteRule ^(.*)$ http://domain.dev/site/%1 [QSA,NC]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Is this even possible?
You're pretty close. In order to not redirect the browser (causing the address bar to change) you need to get rid of the http://domain.dev part of the rewrite rule's target:
RewriteRule ^(.*)$ /site/%1/$1 [QSA,NC]
assuming that both *.domain.dev and www.domain.dev have the same document root. If they're different, you may have to enable mod_proxy and add a P flag so that the request gets proxied instead of redirecting the browser:
RewriteRule ^(.*)$ http://domain.dev/site/%1/$1 [QSA,NC,P]
I have a pretty basic CodeIgniter setup for a site that now needs to be run entirely on SSL. So, I figured I need to force https by some .htaccess rules as that seems to be the most intuitive and straight forward approach. This is what I do:
config:
$config['base_url'] = 'https://cooldomain.com';
$config['index_page'] = '';
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#remove ugly index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
The result is that I get lots of identical GET requests in my FireBug resulting in a "blank" error screen.
Doesn't CI URI patterns like .htaccess redirects? Surely this must work?
Shouldn't
RewriteCond %{S} off
actually be
RewriteCond %{HTTPS} off
?
Because this answer came up quite high on my google search I'll answer this one.
Reading from the comments there seems to be a loadbalancer infront of the webserver. When this happens you can check the following as well to see if there's a https connection:
RewriteCond %{HTTP:X-Forwarded-Proto} =http