Reputation: 23
/tv-shows/survivor/
<a href="/tv-shows/survivor/"></a>
/tv-shows/survivor/season-37
<a href="/tv-shows/survivor/season-37"></a>
/tv-shows/survivor/season-37/episode-8
<a href="/tv-shows/survivor/season-37/episode-8"></a>
This how I want to structure the website navigation. I have different nested folders where php files are stored. In (tv-shows) folder i store series names files. Like survivor.php and (season) folders . In (season) folder i store seasons files like season-37.php and (Episodes) folders. In (Episodes) folder i store all episode names like episode-8.php.
I want to know how to structure this kind of .htaccess to achieve this kind on structure.
Upvotes: 0
Views: 40
Reputation: 28871
You can store all you files in sub-directories like so:
tv-shows/
index.php (for /tv-shows)
survivor/
index.php (for /tv-shows/survivor)
season 1/
index.php (for /tv-shows/survivor/season-1)
episode-1.php (for /tv-shows/survivor/season-1/episode-1)
episode-2.php
...
season 2/
index.php
episode-1.php
episode-2.php
...
To remove the .php extension you can add the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
However I recommend just moving to a proper framework that has a routing feature as your asking for a mantainence nightmare.
Have a look at: Laravel, or a dedicated PHP routing library AltoRouter. A framework would be better however.
Upvotes: 1