1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need some help with PHP!

Discussion in 'PHP' started by seo_sensey, Jul 24, 2004.

  1. #1
    Hi!
    First of all I want to say I found your forum when I signed up for the Keyword Tracking tool and after reading a few threads ( which seemed to be very informative regarding the subjects that were debated ) I decided to join.

    Now, I'm a php newbie, just started a few weeks ago but I can't solve this problem at this moment. Here is my problem:

    Recently I noticed some issues for one of my sites' pages listed in Yahoo! index. I have a hosting account where is host 2 domains, 1 is an addon domain and points to a subdomain of the main domain of the account.
    Something like this: main domain of the account is domain.com and the second domain ( domain2.com ) points to sd.domain.com.
    Now the problem is that I have many directories for domain2.com which in order to work properly need an ending "/" ( like: www*domain2*com/directory/ not www*domain2*.com/directory ) which Yahoo! picked up without the ending "/" and shows them in the serps without it like: www*domain2*.com/directory , and when surfers click on it they get and error page . I see no problem with Google which picked them with the ending "/" .

    I asked the same question on SEOCHAT and a nice member gave me a solution, something like this:
    <?
    $requested_domain = $_SERVER['SERVER_NAME'];
    $requested_page = $_SERVER['REQUEST_URI'];
    
    if ($requested_domain == "subdomain.maindomain.com") {
    header("Location: http://www.addondomain.com/".$requested_page);
    }
    
    ?>
    
    Code (markup):
    but at that moment I didn't pay to much attention because I though it will work ( my bad mistake :( )

    Now, it seems it doesn't so if anyone can give me a clue on this I would be very thankful.

    Thank you!
     
    seo_sensey, Jul 24, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Are you just wanting to add a slash to the end of the URL?

    If so, something like this may work...

    <?
    if (substr ($_SERVER['REQUEST_URI'], -1) != "/") header ("Location: http://" . $_SERVER['SERVER_NAME'] . "/" . $_SERVER['REQUEST_URI'] . "/"
    ?>
    PHP:
     
    digitalpoint, Jul 24, 2004 IP
  3. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I do not belive you can solve this with php. It is really a server issue in that "www*domain2*.com/directory" defults to a file rather than a directory.

    www*domain2*.com defults to www*domain2*.com/index.html (.php, .etc)
    www*domain2*.com/directory/ defualts to www*domain2*.com/directory/index.html
    www*domain2*.com/directory defualts to www*domain2*.com/directory.html

    use 1 of 3 solutions
    1 change sever settings
    2 use htaccess file
    3 do not use "directory/index".html(.php, .etc)
     
    mushroom, Jul 24, 2004 IP
  4. Foxy

    Foxy Chief Natural Foodie

    Messages:
    1,614
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    IMHO Surely this is a rewrite or redirect in apache?

    That is, the person accessing from Yahoo gives www*domain2*.com/directory as the link and so arrives at your site incorrectly

    so you need to redirect from this url to the proper url
     
    Foxy, Jul 25, 2004 IP
  5. seo_sensey

    seo_sensey Active Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    Ok ... I've been searching different sources on the net to find a clue for this issue.

    Here's what I got:

    ---http://httpd.apache.org/docs/mod/mod_dir.html

    Someone recommended me to add directoryIndex tag to my .htaccess file.

    The problem is I Know nothing about .htaccess cuz I never had to use it.
    If someone could tell me how this should be done I would be very very thankful. Btw ... I'm using Cpanel X.

    Thank you ... I'm looking for a clue reply!
     
    seo_sensey, Jul 26, 2004 IP
  6. Foxy

    Foxy Chief Natural Foodie

    Messages:
    1,614
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Foxy, Jul 26, 2004 IP
  7. seo_sensey

    seo_sensey Active Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #7
    Hey Foxy.
    Thanks again for your reply.
    Before I came here to post and ask for help I tried to set a 301 redirection through Cpanel but it is not possible.

    My addon domain points to a subdomain of the main domain.
    Even so ... i did a redirect of xxxwww.maindomain.com/subdomain/directory to xxxwww.addondomain.com/directory/ but it still doesn't work
     
    seo_sensey, Jul 26, 2004 IP
  8. Owlcroft

    Owlcroft Peon

    Messages:
    645
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I am fairly sure that this would work for you, where dirpathX is the name (or full path) to some one directory you need to deal with. I do not pretend this is the only or best way; I am not a regex expert.

    <IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} www\.domain2\.com [NC]
    RewriteRule ^dirpathA$ http://www.domain2.com/dirpathA/ [L,R]

    RewriteCond %{HTTP_HOST} www\.domain2\.com [NC]
    RewriteRule ^dirpathB$ http://www.domain2.com/dirpathB/ [L,R]

    RewriteCond %{HTTP_HOST} www\.domain2\.com [NC]
    RewriteRule ^dirpathC$ http://www.domain2.com/dirpathC/ [L,R]

    </IfModule>
    You could simplify that one-line-pair-per-directory mess if you can find some "regular expression" that uniquely specifies your set of directories.

    In that set of directives, let us assume that you have a subdirectory named /packages that you need to handle.

    The Rule for that directory would then be:
    RewriteRule ^packages$ http://www.domain2.com/packages/ [L,R]

    You can do the same for deeper subdirectories:

    RewriteRule ^packages/new$ http://www.domain2.com/packages/new/ [L,R]

    The problem is complicated by the fact that there is no simple a priori way (that I know of) to determine if a call not terminated by a slash is or is not a legitimate call for a valid filespec--so we can't just rewrite any call not ending in a slash, because it might be for a real file.

    Now, if we could make two assumptions--

    1. No directory name, at any level, contains (or starts or ends with) a period; and,

    2. All valid file names, at least within the directories at issue here, do have at least one embedded period in (or at the start or end of) their names--

    then we could simply the core directives (I think) to this:

    RewriteCond %{HTTP_HOST} www\.domain2\.com [NC]
    RewriteCond %{REQUEST_URI} !^.*\..*$
    ReWriteRule ^(.*) http://www.domain2.com/$1/ [L,R]
    Don't take this to the bank, but I believe that would work, given those two assumptions.
    The second condition is my attempt to write a regex that translates to--

    NOT stuff.morestuff
    --where "stuff" is anything whatever except a period, and morestuff is anything whatever.

    Those who know regex better can correct that if it's in error.
     
    Owlcroft, Jul 26, 2004 IP
  9. seo_sensey

    seo_sensey Active Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #9
    Thanks a lot Owcroft and all the other guys that tried to help me.
    My problem was solved by my host.
    Anyway, for everyone who may have this kind of problems in the future ... they said it was about UseCanonicalName tag that must be disabled in httpd.conf in order for an addon domain to work without the ending " / "
     
    seo_sensey, Jul 26, 2004 IP