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 supposed to be a category homepage for /category-games/. Is there any way to make this page show when someone visits mysite.com/category-games/? I tried to put the page into the folder and called it index.php but I guess that's not working.
Probably need to do this via .htaccess. Anyone can help me with this? Right now if anyone tries to access mysite.com/category-games/its going straight to 404.
Cheers!
Case 1: If /category-games/ has no .htaccess then place this rule in root .htaccess:
RewriteEngine On
RewriteRule ^category-games/$ games.php [L,NC]
Case 2: If there is a .htaccess inside /category-games/ then use this rule
RewriteEngine On
RewriteRule ^/?$ /games.php [L]
Well, if you are thinking about in a organize and systematic coding, then I would like to suggest you to use PHP Routing library. There are many ready mate routing classes available. If you want to use that, surely it will help you to make your code more organized way.
For example, if you want to access mysite.com/category-games/, behind the scene, routing will trigger your corresponding page.
Following code will try to access mysite.com/category-games folder but it will trigger out your-page.php file where user can see only mysite.com/category-games url, nothing else.
$router->any('/category-games', function(){
return 'your-page.php';
});
Isn't cool?
The list of routing library are-
Hope, will help you to do your project. TQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With