Forum Moderators: coopster

Message Too Old, No Replies

need to force index.php?page=home

and not just index.php or example.com

         

php4U

2:27 am on Aug 25, 2008 (gmt 0)

10+ Year Member



header won't work because you are trying to redirect to the same page, but with a query string behind it.

The site I am working on uses strings, and my menu is built so the current page displays the rollover image to indicate what page you are on.

When the user types example.com/index.php or just example.com I need it to default to example.com/index.php?page=home since that is the default page in my menu.

I would like to use php to do this if possible, .htaccess seems to be a little quirky on their server. Thank you for any suggestions.

MattAU

3:09 am on Aug 25, 2008 (gmt 0)

10+ Year Member



I don't think it's possible via PHP without header().

Why not just if(empty($_GET['page'])) $_GET['page'] = 'home'; ?

php4U

5:24 am on Aug 25, 2008 (gmt 0)

10+ Year Member



Thank you MattAU

I am currently using "isset" but my code is the same as the rest of your example. I tried changing it to "empty" and it didn't show the highlighted menu item for home. I might be able to use empty and leave it blank between the single quotes, but I would still have to find a way to get to the ?page= string in the browser.

Once the site is complete, I might have to resort to a 301 redirect from their old .html index file to the new php file with the string on the end. Thanks again.

g1smd

4:14 pm on Aug 25, 2008 (gmt 0)

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



It is quite likely that all of these URLs will return the same content.

example.com/
example.com/index.php
example.com/index.php?
example.com/index.php?page=
example.com/index.php?page=home
example.com/?page=
example.com/?page=home
www.example.com/
www.example.com/index.php
www.example.com/index.php?
www.example.com/index.php?page=
www.example.com/index.php?page=home
www.example.com/?page=
www.example.com/?page=home

Search engines will prefer to list this one: www.example.com/

All of the others are duplicates.

It's generally considered bad form for the bare root URL to redirect to an internal/deep URL.

It should be easy enough for you to detect that the URL request was for root, and display the right stuff.

All of the other formats should redirect to the bare www.domain.com/ format if requested.

g1smd

4:34 pm on Aug 25, 2008 (gmt 0)

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



If you really can't modify your PHP script, then do this in your .htaccess file instead:

- let all of the alternative URL formats for that home page all externally redirect to exactly www.domain.com/ using a 301 redirect.

- set up an internal rewrite such that a request for the URL www.example.com/ is internally rewritten to fetch the content from this internal filepath /index.php?page=home without exposing what that filepath actually is.

You will need to also make sure that all of the internal "Home" links within the site are pointing to "/" or to "www.domain.com/" and not to any of the alternative formats.

willis1480

8:35 pm on Aug 25, 2008 (gmt 0)

10+ Year Member



read-up on .htaccess..you can control what your actual URL looks like depending on what someone entered and what content to display.

You can perform regular expression matches on the requested URL and decide where to send those requests.

[edited by: eelixduppy at 9:07 pm (utc) on Aug. 25, 2008]
[edit reason] removed URLs [/edit]

php4U

1:06 am on Aug 27, 2008 (gmt 0)

10+ Year Member



Thank you for the additional replies. The CMS system I am using has a "top" level page that can't be deleted and shows by default. In looking at this the page is actually ?page=home but since it's the default page it shows with just domain.com and no string as well.

Perhaps changing my existing code might be the easiest solution, since I discovered the home content shows with just domain.com

<?php //home
if (isset($_GET['page']) && $_GET['page'] == 'home') {

echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}

else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>


The above works properly when ?page=home is in the URL, but possibly "isset" can be modified to use that ALONG with domain.com since "home_roll.gif" doesn't show when it's only domain.com. Maybe using "OR" somehow in the above statement... ?page=home OR domain.com { echo this } else { echo something else } ?

Thank you

g1smd

9:48 am on Aug 27, 2008 (gmt 0)

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



For the image link:

<img src=\"images/home_roll.gif\"

try changing that to:

<img src=\"/images/home_roll.gif\"

.

Likewise for:

<img src=\"images/home.gif\"

try changing to:

<img src=\"/images/home.gif\"

php4U

1:01 am on Aug 28, 2008 (gmt 0)

10+ Year Member



The images show up fine...built using "images" on the development server since I was working in a subdirectory. I'll switch them to /images on the actual customer server where images with be the storage place at the main directory level.

Anyone have a suggestion about the ?page=home and domain.com so the above code works for both?

php4U

3:43 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Ok, I found that this works somewhat. I see the logic in why it's doing it, but I'm not sure how to get around it. The following displays the "home_roll.gif" image when index.php (same as domain.com) and index.php?page=home are both accessed. The issue is now if you select another page like index.php?page=another_page since index.php is still present the same "home_roll.gif" is displayed, but I only want the page I'm on to show the rollover image.
<?php
$page =& $_SERVER['SCRIPT_NAME'];
if (isset($page) && $page == '/index.php' OR (isset($_GET['page']) && $_GET['page'] == 'home')) {

echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}

else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>


This is sort of tricky because each menu item has this code to show the specific image according to if it's selected or not, and I don't think I can use a switch statement to show the default images such as "home.gif" if that particular page isn't selected.

Anyone have any ideas? Thank you