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]
Related
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]
I'm trying to set up an SSL for a site using Codeigniter.
I need to to force https:// on certain pages (such as login, basket etc).
What I have so far, which forces www. successfully, and removes the index.php from the URL for cleaner results with Codeigniter:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Keep your redirect rules before rewrite ones:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{THE_REQUEST} /(login|basket|shop)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I have this in my .htaccess file
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteCond %{REQUEST_METHOD} !POST$
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
How can i Redirect my website from http to https and also avoid index.php?page= from the pages?
You can do:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
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]
I have the following code and I am trying to do something like that. Let's say I have an address - mydomain.com/server2/ when I type anything after slash for example mydomain.com/server2/whatever I want to load server2.php but address has to be the same
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# remove index.php
RewriteRule ^index\.php/?$ / [L,R=301,NC]
# Hide File Extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
# Add 301 redirects to new extensionless file
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.mydomain.com/$1 [R=301,L]
# Add the trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://www.mydomain.com/$1/ [R=301,L]
</IfModule>
also I don't know if above code is 100% correct. Thanks for any help.
There are problems in your code and in certain URLs it will give you infinite looping. Replace your code with this:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L,NE]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
# Add the trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
</IfModule>