Http to Https not working for inner pages - php

I have made all necessary changes to convert to https but not working for inner page.
Here is my .htaccess
# Use PHPBETA Single php.ini as default
AddHandler application/x-httpd-phpbetas .php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://example.ae/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Note: It is working for home/main page like https://example.com. It says its secure. But when i visit https://example.com/otherPage it says insecure.
Note: My website is developed in CodeIgniter. I also changed url in config.php file.
Ref: I followed all these steps
Any Idea??

Try this code. I am using in codeigniter. Also make sure you used base_url() or site_url() in linking nav.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You should make all your css, js images on your page come from https URL too, this will resolve your issue.

Related

.htaccess code to make http go to https with a CodeIgniter complication

I use codeigniter with some URL routing.
I want to migrate from http to https.
This is my current .htaccess code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^eternalcitytours\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX [NC]
RewriteRule ^(.*)$ http://eternalcitytours.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
# Development
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
The above works fine on http.
To go to https i changed the .htaccess to be:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://eternalcitytours.com/%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^eternalcitytours\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^037\.061\.237\.216 [NC]
RewriteRule ^(.*)$ https://eternalcitytours.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
# Development
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
However, the above code doesnt work as I get 2 problems:
whenever incoming traffic comes to me from an http link, the resultant url has an extra / in it: e.g. https://eternalcitytours.com//en/5/About-Eternal-City-Tours instead of https://eternalcitytours.com/en/5/About-Eternal-City-Tours
If someone has https://WWW.eternalcitytours.com then the page wont load and an error is given. (ERR_SSL_PROTOCOL_ERROR)
Can someone help with my .htaccess code as i honestly dont know what i'm doing.
thanks
You need to use this rule for http -> https:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://eternalcitytours.com%{REQUEST_URI} [R=301,NE,L]
Note / removed before %{REQUEST_URI}.
Make sure to clear browser cache before testing it.
For problem #2 it seems your SSL cert is for eternalcitytours.com domain only. It is because SSL handshake hapens before mod_rewrite rules are executed and there is no rule based fix except that you keep https links with www in your HTML source.

.htaccess redirection issue in codeigniter

I am working in a site which has been developed in codeigniter,
To remove index.php from url I wrote rewrite rule in htaccess, now , there is anotheher need to be arise, that is I need to replace http:// to www in url,for that I wrote the code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^vrinfosystem.com$
RewriteRule (.*) http://www.vrinfosystem.com/$1 [R=301,L]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
but I got issues, the stylesheet and js are no found.
I changed the base url too but it didn't help.
if I wrote following line above the HTTP_HOST
RewriteRule ^(.*)$ index.php?/$1 [L]
the it will work fine but the index.php will retain in url.
Ho can I solve this issue?
are u sure u have changed your config?
if you don't go to application>config>config.php than scroll down till you find this
$config[‘index_page’] = 'index.php';
change it too
$config[‘index_page’] = '';
There are a group of different scripts for this. This is the only one that worked for me across several sites
RewriteEngine on
RewriteCond $1 !^(index\.php| (.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

Codeigniter remove index.php and prefix the URL with www

I want to remove the default index.php that auto comes with Codeigniter.
I've been able to remove that with this code
RewriteRule ^(.*)$ index.php/$1 [L]
example.com/index.php/blog can now be accessed by example.com/blog
I later wanted to prefix the URL with a www i.e example.com/blog should redirect to www.example.com/blog with these rewrite rules
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
After adding this code above to the end of my .htaccess file, it began to misbehave.
If I enter www.example.com/blog into a URL bar it works fine but if I enter example.com/blog it redirects to www.example.com/index.php/blog
What I'm I doing wrong?
I want example.com/blog to redirect to www.example.com/blog
Note: I am using the Codeigniter framework.
Added: This code is just on top of the previous ones I have up. Maybe this is it's problem please HELP!!!
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
Try this:
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ example.com/$1 [L,R=301]
After much tricks and following the post given by #Tpojka I was able to come up with this
RewriteEngine On
RewriteBase /
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# no www -> www
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This guy was my problem
RewriteCond $1 !^{index\.php|[assests/images/themes/fonts/style/scripts/js/install]|robot\.txt|favicon\.ico}
I would need help on how to exclude folders and some files like robot.txt file like I tried in the malfunctioning line.
This is the complete .htaccess file which I use personally:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

url rewriting not working on one.com provider

Currently i am trying to get url rewriting to work on one.com hosting provider which is a pain and support don't understand the issue, so i was thinking of asking here if you may assist me finding the issue.
I'm using this rewriterule which worked on localhost but not with the provider:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?key=$1&seo=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?key=$1&seo=$2
</IfModule>
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www\.mysite.com/$1 [R=permanent,L]
and in index:
if($key=='post') //Cant include $seo here because the variable differ for
//each post on the site
{
include('post.php'); // Post page
}
Then in post.php ofc i take the seo GET variable to display the post content on the page.
complete url www.mysite.com/post/test-test-test
The error i end up with is 404
Not Found
The requested URL /post/test-test-test.php was not found on this server.
So basically what i understand is that it tries to enter a folder named /post/ and look for the file test-test-test.php
So i believe it doesn't include the rewrite rule, or can you find an error in the rewrite rule which worked on localhost?
You need to rearrange your rules and for adding .php extension make sure a file with .php exists:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
# ignore rest of the rules for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/?$ index.php?key=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?key=$1&seo=$2 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
</IfModule>

Combine htaccess rewrites

I am using php CodeIgniter and have the following rewrite rule in my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Since I want the users to use the site through SSL, I would like to add the following rewrite rule:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]
However, when I do that, every page in a subdirectory will have /index.php/actual_page - the index.php before that is not desired. I thought that might come from having RewriteRule ^(.*)$ index.php/$1 [L] in there, but without the RewriteRule ^(.*)$ https://www.link.com/$1 [R,L] it works fine.
So, how can I rewrite the url to https without breaking the first rewrite?
Make sure the https redirect happens before the rewrite to index.php. You want it to look something like this:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Categories