Forum Moderators: coopster
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.
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.
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.
- 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.
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]
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>";
}
?>
Thank you
Anyone have a suggestion about the ?page=home and domain.com so the above code works for both?
<?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>";
}
?>
Anyone have any ideas? Thank you