How to set an index page in a subfolder
I have the following file / folder structure for my site:
index.php games.php /category-games /category-games/game-1.php /category-games/game-2.php
The file games.php
is assumed to be the home page of the category /category-games/
. Is there a way to show this page when someone visits mysite.com/category-games/
? I tried to put the page in a folder and named it index.php but I think it doesn't work.
You probably need to do this via .htaccess. Can anyone help me? Right now, if anyone tries to access it mysite.com/category-games/
, it will go straight to 404.
Hooray!
source to share
Try creating a new page called index.html in the / category-games / category with the following content:
<meta http-equiv="refresh" content="1;url=http://yoursite.com/category-games/games.php">
This will make index.html load by default, but will instantly redirect to games.php. 1 is the time to wait before redirecting. 1 is best, so it doesn't overload your browser.
Toodles!
-HewwoCraziness
source to share
Well, if you are thinking about organization and systematic coding, I would like to suggest that you use the PHP Routing library. There are many ready-made routing mate classes. If you want to use this, it will certainly help you keep your code more organized.
For example, if you want to access mysite.com/category-games/
, behind the scenes, routing will bring up your corresponding page.
The following code will try to access the mysite.com/category-games folder, but it will output your-page.php file where the user can only see the url mysite.com/category-games, nothing else.
$router->any('/category-games', function(){
return 'your-page.php';
});
Not cool?
Routing Library List -
Hope it helps you to make your project. TQ
source to share