Link to home
Start Free TrialLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

Redirect only home page with php

In order to consolidate back link credit, and avoid a ranking penalty for duplicate content, I would like to redirect requests for my landing page from the www to the non-www version.  I don't want to use .htaccess to redirect every page in the site, because there are scripts on my site which require the www prefix, so I only want to redirect the landing page.  

I would prefer not to change the suffix of my landing page to php.  I believe that .htaccess can be coded so that the Apache server treats all htm pages as php, but I don't know what unexpected effects that might have.

Here is the snippet which I would like to include in my landing page:

<?php if ($_SERVER['HTTP_HOST'] == 'www.mauitradewinds.com'){
header("Location: http://mauitradewinds.com".$_SERVER['REQUEST_URI']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

Please advise if, and how, this could work.
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

You could even redirect it from your dns panel.
Please check with your hosting control panel for the same, no changes in code nor in your .htaccess
Avatar of ddantes

ASKER

Thank you.  Just to be clear, are you suggesting that the dns panel could be configured to redirect only the landing page, and not the other pages within the site?
yes. It means if client tries to hit  mauitradewinds.com it  will be redirected to www.mauitradewinds.com .
If you could paste the .htaccess file it would great to resolve your issue
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ddantes

ASKER

Thank you both for your comments.
insoftservice:  I'm still uncertain about this.  It seems that changing the dns "target" would affect the entire site, not just the landing page.   It's good if www.mauitradewinds.com is redirected, but I don't want www.mauitradewinds.com/RezEasy to be redirected, or any other subfolder, or deeper pages on the domain.  That is why I am hesitating.

Ray_Paseur:  This looks promising.  I was concerned about parsing all pages through the PHP parser.  Are there any drawbacks to doing that?
"Any" is a very big word, sort of like "never."  You could make the argument that unnecessary PHP parsing introduces server overhead.  In my experience, the overhead was undetectable and the advantages of having PHP available in all my scripts greatly outweighed any perceived disadvantages, so I used it.
Avatar of ddantes

ASKER

Fair enough!
Avatar of ddantes

ASKER

I implemented the change to .htaccess, and my browsers now ask me if I want to open or download the home page.  I changed .htaccess back to its previous version so that my site remains available.
That sounds odd.  Where is your site hosted?
Avatar of ddantes

ASKER

User generated image
The host is ulysium.net  which uses Apache software on a Unix platform.
Here is a screenshot of Firefox loading the landing page with that .htaccess in place.
Avatar of ddantes

ASKER

If it is useful, here is a link to the server's php info...
http://mauitradewinds.com/PHP-info.php
OK, this is an unfamiliar PHP version and Linux build.  Here's what I recommend.  Contact the server administrator or help desk.  Show them the line in .htaccess that I showed you.  Ask them what their equivalent statement should say to cause HTML files to be parsed through PHP.

You might also want to ask them to move your site to a server that does not have Suhosin.  That thing, while well-intentioned, will cause a catastrophe for you one day.  A clue as to its efficacy is the copyright date which is many years old.  It will do things like throw away request variables without notice -- the kind of thing that people who were ignorant of security and good programming practices would do to try to "foil" attackers.  Fortunately PHP has come a long way since then, and Suhosin is no longer needed at all.  It's all risk and no reward to have your scripts on a Suhosin-infected server!
Avatar of ddantes

ASKER

Very good.  Thank you for your input, and  I'll find out how that server wants to parse html through PHP.