Pages 404ing when on https:// - .htaccess

I've just installed an SSL on my server and enabled https on my websites admin area however now when normal pages are accessed with https:// instead of http:// I get a 404 page. This is my htaccess, it has the standard expressionengine index.php removal in as well but I can't work out what I need to change to make https:// work if front-end pages are accessed with it, any ideas?:
<IfModule mod_rewrite.c>
RewriteEngine On
# force https for all URLs in /admin.php
RewriteCond %{HTTPS} =off
RewriteRule ^admin.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Replace all of your code with this:
RewriteEngine On
# force https for all URLs in /admin.php
RewriteCond %{HTTPS} off
RewriteRule ^admin\.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !/system/ [NC]
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Related

How to redirect http to https://www.example.com using htaccess file?

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I have created a website using Codeigniter framework and my domain and hosting is on GoDaddy. Now, I have installed SSL certificate and manage with my website. Now, when I use example.com in URL it redirects me on https://www.example.com but when I click on my login page it shows me Not Found and URL looks like https://www.example.com/index.php?/login but I want URL Like https://www.example.com/login. So, How can I do this? Please help.
Thank You
Change order of your rules
Have a single rule to redirect www and http -> https
Your .htaccess should be like this:
RewriteEngine on
# redirect for adding www and https
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Make sure to use a new browser for your testing.
Please use this htaccess rules will work 100%
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
use this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Friendly URL redirection not working

I've trying to use url redirection for 3 things:
Redirect to HTTPS
Redirect from domain.com to www.domain.com
Redirect from friendly url to real url without changing the url in the browser
The problem is that redirecting from friendly url, changes the url to the real one. I'd like to avoid it. Any suggestion?
Here's the piece of code in htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^inconclusos.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)/?$ https://www.example.com/index.php?s=$1 [L]
</IfModule>
Thanks,
Pau
RewriteEngine on
# FORCE DOMAIN #
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.tld$ [NC]
RewriteRule ^(.*) https://www.domain.tld/$1 [R=301,L]
# FORCE HTTPS #
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
# FRIENDLY URL #
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?s=$1 [L]

To remove .php AND send to https from http connection

We moved the the whole site from http:// to https:// this works fine if you arrive at the site via https://. However all the previously cached urls (in Google) on http:// need to be redirected. Also we had previously been using a rewrite to take out .php in the urls and want to keep this. But this is where we are having problems.
The redirect we have from http to https pages in whole site which works with the htaccess below, but it does not remove the .php extension on those redirects.
Have tried these
Force HTTPS on certain URLs and force HTTP for all others
Here is the problem
Here is an example old url, see how it get rewriiten with .php not removed.
http://www.myitalianliving.com/product/1105/translucent-stackable-indoor-outdoor-chair-cooler-by-scab
Here is the site
https://www.myitalianliving.com/
Here is the .htaccess file
RewriteEngine on
## provide ip address redirect to canonical and SEO puproses
## see: https://stackoverflow.com/questions/9985735/redirect-ip-to-domain
#
#RewriteCond %{HTTP_HOST} ^81\.29\.78\.50$ [NC,OR]
#RewriteCond %{HTTP_HOST} ^([a-z.]+)?myitalianliving\.com$ [NC]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://www.myitalianliving.com/$1 [R=301]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index\.html$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index\.htm$ https://www.myitalianliving.com/ [R=301]
## added below as in testing we had just the .com/index in the url no extension.
RewriteRule ^index https://www.myitalianliving.com/ [R=301]
#
##########################
# Try to remove .php AND send to https from http connection
##########################
Options +SymlinksIfOwnerMatch +MultiViews
#
#### RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##### RewriteRule ^(.*).php/(.*) $1.php?$2
RewriteRule ^(.*?).php/(.*?) $1.php?$2 [NC]
#
## https://stackoverflow.com/questions/4398951/force-ssl-https-using- htaccess-and-mod-rewrite
#
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You need to move your HTTPS redirect to the top of your set of rules:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## provide ip address redirect to canonical and SEO puproses
## see: http://stackoverflow.com/questions/9985735/redirect-ip-to-domain
#
#RewriteCond %{HTTP_HOST} ^81\.29\.78\.50$ [NC,OR]
#RewriteCond %{HTTP_HOST} ^([a-z.]+)?myitalianliving\.com$ [NC]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://www.myitalianliving.com/$1 [R=301]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.myitalianliving.com/ [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/
RewriteRule ^index\.html?$ https://www.myitalianliving.com/ [L,R=301]
## added below as in testing we had just the .com/index in the url no extension.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/ RewriteRule ^index https://www.myitalianliving.com/ [L,R=301]
#
##########################
# Try to remove .php AND send to https from http connection
##########################
Options +SymlinksIfOwnerMatch +MultiViews
#
#### RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##### RewriteRule ^(.*).php/(.*) $1.php?$2
RewriteRule ^(.*?).php/(.*?) $1.php?$2 [L,NC]
Additionally, you need to add conditions to the index redirect rules and use the L flags (just in case).
Moving HTTPS redirect to the top worked with the following redirect at the bottom.
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
# Rewrite URLs for processing by router (article.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/(.+)$ article.php?url=$1 [QSA,L]
# Rewrite URLs for processing by router (product.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/(.+)$ product.php?url=$1 [QSA,L]
# Rewrite URLs for processing by router (page.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.+)$ page.php?url=$1 [QSA,L]
# Rewrite URLs for processing by router (section.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ section.php?url=$1 [QSA,L]

prevent Q2A redirecting addon domains?

I have the Q2A script installed http://www.question2answer.org/
I have non-www. & non-https redirecting to www & https perfectly but, somewhere within the htaccess code it's redirecting my add-on domain http://addon-domain.com to https://www.main-domain.com/addon-domain.com/
I suspect it's something to do with the following but, have no idea how to edit it correctly:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Here's the whole code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# redirect any domain other than www.main-domain.com to www.main-domain.com
RewriteCond %{HTTP_HOST} !^www\.main-domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
# force https on www.main-domain.com
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>

https in htaccess and order of rules (using Expression Engine)

I'm building a site in expression engine that part of needs to be https. The site is also using a new domain name (new one www.example-new.com the old one www.example.old.com).
I want to do the following things:
remove the index.php
force www
force https for any url starting www.example.old.com/extranet
redirect https URLs that are not www.example.old.com/extranet (e.g. www.example.old.com/news to http
I have the following code so far that works for the first two requirements:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} ^example-new.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
AddType x-httpd-php53 .php
I seem to be going round in circles, so I've two questions that will help me write the other rewrites (although feel free to share suggestions...):
1) Should the code for requirements 3 and 4 be positioned before "removes index.php" code?
2) Does the position have any bearing on the redirects that will be coming from the old site e.g. www.example-old.com/some-link-here.asp will be redirected to www.example-new.com/some-new-link-here
Thanks,
Gregor
1) Remove 'index.php' from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
2) Add 'www' to all URIs
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
3) Force https:// for any URI starting with /extranet
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/extranet(.*)$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
4) Redirect https:// URIs that are not /extranet
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/extranet(.*)$ [NC]
RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
Putting it all together, here's your complete set of RewriteRules:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/extranet(.*)$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/extranet(.*)$ [NC]
RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
1) Should the code for requirements 3 and 4 be positioned before "removes index.php" code?
The rules are processed in the order that you write them. I expect that you want the site to redirect first then do the remove index, so yes, it should go before
2) Does the position have any bearing on the redirects that will be coming from the old site e.g. www.example-old.com/some-link-here.asp will be redirected to www.example-new.com/some-new-link-here
If you are using the same directory for both sites, then you would need to prefix all rules for one site with a RewriteCond that limits the domain. Otherwise, order of the rules (old vs new site) is important.
Your redirects from the old site should also incorporate rules in the new e.g. ensure that you are going to http/s as necessary to avoid extra redirects.
Below is the code to force http/s
#if not secure
RewriteCond %{HTTPS} off
#and starts with /extranet
RewriteCond %{REQUEST_URI} ^/extranet [NC]
#redirect to secure
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#if secure
RewriteCond %{HTTPS} on
#and does not start with /extranet
RewriteCond %{REQUEST_URI} !^/extranet [NC]
#redirect to http
RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force www on hostname, but keep same protocol (http/https)
RewriteCond %{HTTP_HOST} !^www\.(.+)
RewriteCond %{HTTPS}s ^(on(s)|offs)
RewriteRule ^ http%2://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If it helps... I just did this yesterday for an ecommerce site... Here's my .htaccess file
# Remove WWW from URL
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)$ $1/ [L,R=301]
#remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
#Force HTTPS on checkout/account pages
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (checkout|account)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#remove HTTPS on all other pages
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(img|_|images|checkout|account)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Resources