?
Solved

.htaccess file settings

Posted on 2016-11-10
4
Medium Priority
?
92 Views
Last Modified: 2016-11-10
Dear Experts,

my htacces file is like below:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I redirect all http pages to https pages, it works perfectly fine.

in addition to this, I want to redirect all page request like

http://google.com to https://www.google.com  ( I want to convert http to https and I want to use also www if my user do not type it )

otherwise google analytics calculate the pages like they are separate pages

could you please help me?

I use php and mysql
0
Comment
Question by:Braveheartli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 41881979
Let me suggest a slightly different concept.  Let your subdomains mean something.  Here are some examples:

example.com -- no subdomain, the canonical representation of your web site
www.example.com- - rewrite to remove www and redirect to example.com
test.example.com -- the test version of your site; do not rewrite
docs.example.com -- the documentation for your site; do not rewrite
api.domain.com -- the RESTful API to your site; do not rewrite

This design will preserve good information for Google Analytics and will allow you to use relative links in your markup.  It's good enough for Twitter ;-)
1
 
LVL 1

Author Comment

by:Braveheartli
ID: 41881990
Dear Ray, thank you very much.

You are right. In the future, I would need subdomains.
Canonical representation is better for my web site.

Sould I do it like this?
if my user request my web site example.com, I should redirect to https://example.com
if my user writes www.example.com, I should use Canonical representation https://example.com 
right?
1
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 41882020
Yes, I would do it that way.  I'm not exactly sure of the rewrite rules (someone else should get the points when they post the rules), but that design makes sense.

Anything else in the subdomain besides test, docs, api should get rewritten to example.com.  Later, if you wanted to add another subdomain, you could open it up by excluding it from the rewrite set.
0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41882025
thank you Ray,
you are great.
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question