Forum Moderators: coopster

Message Too Old, No Replies

Detection of Home page using variables

         

toplisek

3:02 pm on Nov 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like to detect Homepage using PHP code like:
if($_SERVER["REQUEST_URI"] != '/') {$level "is_front_page");}else {$level "is_home");}

Is this correct code or how to be improved?

toplisek

4:39 pm on Nov 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like to detect Homepage using PHP code like:
if($_SERVER["REQUEST_URI"] != '/' || $_SERVER["REQUEST_URI"] != '/index.php' || $_SERVER["REQUEST_URI"] != "" ) {$level "is_front_page");}else {$level "is_home");}

Is this correct code or how to be improved?

If I understand code should support
1. [url]www.yourdomain.com[/url]
2. [url]www.yourdomain.com/[/url]
3. [url]www.yourdomain.com/index.php[/url]
4. subdomain.yourdomain.com

aakk9999

5:07 pm on Nov 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



|| $_SERVER["REQUEST_URI"] != '/index.php'

You are comparing whether the URI is exactly /index.php - which is only true if you control your query string very tightly and home page NEVER has any QS parameters.

But...
- what happens if you add spurios parameter to index.php? Do you still render the home page?
- what happens if you add tracking parameters to home page (such as gclid or utm_something)? Do you still render the home page?

So the answer to your question is difficult without knowing what kind of logic your CMS uses to decide whether to build the home page or not - and this is the same logic you should be using to determine whether it is a home page or not.

Or is this why you try to detect whether it is home page or not? To know which content to return as a response?

toplisek

10:04 pm on Nov 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. Can you post spurios parameter to index.php to check possibility?
2. gclid or utm_something is usually managed by landing page. Serious web marketing manager will never redirect (gclid) to homepage location.

lucy24

10:27 pm on Nov 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what happens if you add ... parameters to home page (such as gclid or utm_something)?

Can't you bypass this problem by replacing the simple "REQUEST_URI == blahblah" with a Regular Expression on the pattern of
^/index\.php(\?\S+)?$

?

I have just this instant-- really-- come from a forum where someone sarcastically observed that some people respond to all problems by constructing a Regular Expression. I am going to make this principle into an embroidered sampler.

aakk9999

3:41 am on Nov 30, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. Can you post spurios parameter to index.php to check possibility?

You can add ?some-param=value to any php script, including the home page one (this is a GET parameter, not POST parameter). Theoretically you can also POST spurious parameters although this is not usually happening when a visitor is browsing - but Googlebot has been known to post spurious parameters just to see 'what is there'.

The question is: if you add request www.example.com/index.php?fakeparam=somevalue (or www.example.com/?fakeparam=somevalue), do you return home page? And if you do, do you need to detect this is a home page?

2. gclid or utm_something is usually managed by landing page. Serious web marketing manager will never redirect (gclid) to homepage location.


gclid was just an example (although I have seen people driving adwords to their home page). But I have definitely sen utm_source etc type of parameters appended to home page URL.

If this should never happen you may develop tight parameters handling and return 404 for requests with spurious parameters you do not expect to receive with index.php. Redirecting to home page may be problematic as if there are too many of these redirects, Google may see it as Soft 404.

toplisek

12:03 pm on Dec 1, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. If you add request www.example.com/index.php?fakeparam=somevalue (or www.example.com/?fakeparam=somevalue), do you return home page? I would leave value as it is without redirection
2. And if you do, do you need to detect this is a home page? I would detect this as Homepage.

Your are right as Google use redirection when clicked searched queries. It means it will detect value and homepage logo will not be detected as homepage.

But it is pure internal redirection policy. It means redirection due to usability issues like logo link directs to Homepage but if Homepage is already there it should hide link inside logo area.

toplisek

1:26 pm on Dec 1, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



See sample:
http://www.example.com/landing-page?utm_source=google& utm_medium=email&utm_campaign=march2012

In this way it is landing-page and it is not included / which will detect as Homepage link (logo area)

toplisek

2:11 pm on Dec 2, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you inform how to put regex in the correct way also option for the google code?
if($_SERVER["REQUEST_URI"] != ''
^/index\.php(\?\S+)?$

lucy24

7:40 pm on Dec 2, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'd use preg_match, wouldn't you? Replace
$_SERVER["REQUEST_URI"] == ""

with something like
preg_match("^/(index\.php(\?\S+)?)?$", $_SERVER["REQUEST_URI"])


But don't quote me. I only do Regular Expressions.

Is "index.php" part of your visible URL? If not, wouldn't you also want to intercept requests that haven't yet been subjected to mod_index activity and/or CMS rewriting? That's why I added the nested (stuff(morestuff)?)?

toplisek

12:18 pm on Dec 3, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have carefully checked and your code should work.

In the case of landing page it will detect Homepage link:
<?php
preg_match("^/(landing-page\.php(\?\S+)?)?$", $_SERVER["REQUEST_URI"]);
if(!preg_match("^/(landing-page\.php(\?\S+)?)?$", $_SERVER["REQUEST_URI"])) {$level == "is_front_page";}else{$level == "is_home_page";}
?>

If I understand code should support also now last option
1. [url]www.yourdomain.com[/url]
2. [url]www.yourdomain.com/[/url]
3. [url]www.yourdomain.com/index.php[/url]
4. [url]www.yourdomain.com/landing-page.php?utm_source=google& utm_medium=email&utm_campaign=march2012 [/url]

lucy24

7:55 pm on Dec 3, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are index.php and landing-page.php different URLs? You can only make a pagename optional (in the Regular Expression) if it truly is optional. Generally this only applies to index pages, unless you're quietly rewriting and the user "thinks" they're on the front page.

:: hoping penders or someone like him reappears before I sau something fatally wrong ::

Incidentally, [ url ] markup only works if there's a leading http:// But you can say [code] if you want it to look different.