如何使这种htaccess

时间:2018-11-21 18:42:00

标签: php .htaccess

/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>

这就是我要如何构建网站导航。 我有不同的嵌套文件夹,用于存储php文件。 在(电视节目)文件夹中,我存储系列名称文件。就像survivor.php和(season)文件夹一样。 在(season)文件夹中,我存储了Seasons文件,例如season-37.php和(Episodes)文件夹。 在(Episodes)文件夹中,我存储了所有情节名称,例如Episode-8.php。

我想知道如何构造这种.htaccess来实现这种结构。

1 个答案:

答案 0 :(得分:1)

您可以将所有文件存储在子目录中,如下所示:

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
          ...

要删除.php扩展名,您可以添加以下内容:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

但是,我建议您改用具有路由功能的适当框架作为您的维修梦night。

请查看:Laravel或专用的PHP路由库AltoRouter。一个框架会更好。