Best way to understand Apache Rewrite Implications

Hi -

A client has the following rewrite code in his .htaccess file:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Open in new window


I would like to :
a) translate each line into an understanding of what the code does (ie. last line means something like "wildcard redirect all links to this domain to the home page", and I think the first line is about forcing www to be in the domain name.  );

b) understand the options to change it should we judge it to be not the best rewrite for SEO.  Here, I am wondering if someone can point us at a good reference for those that don't write apache code often.

Final question:  what if the domain is going to https -- must that be described in this code?

Thanks -
Scott
webdirexionAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lucas BishopClick TrackerCommented:
a) translate each line into an understanding of what the code does (ie. last line means something like "wildcard redirect all links to this domain to the home page", and I think the first line is about forcing www to be in the domain name.  );

Deciphered:

RewriteCond %{HTTP_HOST} !^www\.

Open in new window


Check to see if the url does not have www prepended.

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Open in new window


If previous condition was met, redirect to a version with www. prepended to the url
If previous condition was not met, do nothing.

For example:
If someone types http://yoursite.com in the browser, they'll be redirected to http://www.yoursite.com
If someone types http://www.yoursite.com in the browser, nothing will happen.

b) understand the options to change it should we judge it to be not the best rewrite for SEO.  Here, I am wondering if someone can point us at a good reference for those that don't write apache code often.

From an SEO standpoint, this rule is preventing your site from being indexed with duplicate content.

Google would potentially treat the following pages as duplicates if you didn't have this rule:
http://yoursite.com/page1.htm
and
http://www.yoursite.com/page1.htm

By employing this rule, you eliminate the possibility of a duplicate, because all "non-www" versions of your site are redirected to the www version.

The only change that would make sense would be a flip-flop (ie. redirect all www to the non-www version).

You wouldn't want Google to index both versions of the page, so this acts as a safety measure.


Final question:  what if the domain is going to https -- must that be described in this code?

If you want to force all connections to use https, you will need a different condition and rule combination.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
giltjrCommented:
Since you do not seem to have any checks for ports (80 vs. 443) I think that if somebody enter https://yoursite.com  they would be redirected to http://www.yoursite.com.

However, if they entered https://www.yoursite.com, there would be no re-write because the hostname starts with www.
0
webdirexionAuthor Commented:
This was a well-crafted answer.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.