Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How to set a website homepage

Hey guys,

I'm making website, which has 3 language mutations.

I have template for each page and than in the lang/page.php I have file with variables which contain the local content.

I also include header to each page. Header contains navigation which has relative paths. All fine.

Since I don't have index.php file, I changed .htaccess to make the correct page viewing as homepage. Still everything fine.

But the problem is, that visitor visit the homepage, navigation relative paths link to url/page.php even though it the page is located in url/en/page.php . How can I fix this?

Right now, I've made index.html file that contains script, that redirects user to the correct page, but I am not proud of having to use this way...

Hope you understand my problem. Thanks, Frank

1 Answer

Valentin Berlin
Valentin Berlin
14,346 Points

You could declare a localization ID variable inside each page of your website and include partials for your header, main and footer depending on the value of this variable. Something like:

<?php

$locID = $_GET["locID"];

if (!isset($locID) {
    include("markupPartials/DEFAULTversion.php");
} else {
    include("markupPartials/".$locID."version.php");
}

?>

When traveling between pages you can pass respective GET value to the next page via hidden form. And the URL will look like the current page name with the GET value at the end to indicate the language.

e.g. "index.php?locID=ES"