NYCPHP Meetup

NYPHP.org

[nycphp-talk] Maybe [ot] Duplicate Content.

Andrew Yochum andrew at plexpod.com
Wed Feb 2 22:20:22 EST 2005


On Tue, Feb 01, 2005 at 04:38:09PM -0500, inforequest wrote:
> >
> Original Message:
> -----------------
> From: Andrew Yochum andrew-at-plexpod.com |nyphp dev/internal group use|
> Date: Tue, 1 Feb 2005 15:05:46 -0500
> To: talk at lists.nyphp.org
> Subject: Re: [nycphp-talk] Maybe [ot] Duplicate Content.
> I do something similar.  I have all domains point an A record at the
> same IP, which normally would cause duplicate content.  To solve that I
> have an include that goes in the my prepend of every site that looks
> something like:
> 
>     $Config['Hostname'] = 'www.somedomain.com'
> 
>     if ($_SERVER['HTTP_HOST'] != $Config['Hostname']) {
>         Header("HTTP/1.1 301 Moved Permanently");
>         Header("Location: http://" . $Config['Hostname'] .
> $_SERVER['PHP_SELF'] . (StrLen($_SERVER['QUERY_STRING'])?
> "?".$_SERVER['QUERY_STRING'] : ''));
>         exit();
>     }
> 
> ... which ensures that the hostname being used to access the requested
> page is the one we want to be called by...  "I'm not Drew, I'm Andrew!"
> I call this "hostname assertion".
> 
> Regards,
> Andrew
> <
> 
> Interesting to see PHP used to "bypass" Apache config...sort of (?)
> 
> What I wonder is why this might be a good thing to do? It won't get called
> unless Apache says it belongs (hence you still have to set all the A
> records) and then this has to tell apache to redirect anyway (which it
> would have done if properly configured).

There are quite a few reasons why I don't let Apache do this.  Its
extremely useful in various situations and for various reasons.  In
general, its a consistent method that works for me and its part of my
usual framework.

If you're on a shared host, you don't always have control over Apache.
For instance, as you pointed out earlier newer CPanel versions park
domains w/ an A record pointed at the same IP, creating dupe content.
On a dedicated box w/ control of Apache you might still use this to
allow less technical people to have a method of managing requested URLs,
add new domains on-the-fly (you actually don't need to have it configed
in Apache if there is only one site on the box), etc.

Having a more complex version than the simple example above lets you
manage how these alternate domains are handled - either by redirecting
to the same desired domain with the same requested path & query string,
or maybe to a specific page.  Think of a site called paintstore.com who
buys latexpaint.com and wants the latter to redirect to
paintstore.com/latex - easily managed if its all handled by your PHP
application.  Or, paintstore.com buys paint.com and wants to convert
that to their main domain.  This is a challenge to perform properly to
maintain your SEP.  You can even transition a user's session between old
and new domain so that there is no interruption for users at the time of
the cutover.  If you have code in there to inspect and manage the
requested URLs you can globally implement 301s, create hooks, etc.  Let
your imagination go.  There is a lot more power in having PHP in there
than just Apache, IMO.

Sure, some of this can be done in mod rewrite. And I do use some mod
rewrite stuff to complement this and even have some PHP to manage mod
rewrite rules.

Your thoughts on this?

> Maybe I ammissing something or maybe it's like mountain climbing?

Well, I don't know about mountain climbing. Maybe its like taking the
road less traveled?

Regards,
Andrew



More information about the talk mailing list