假设我在Apache服务器上有一个具有此文件夹结构的静态网站:
http://www.example.com
|
+-- /news/
| |
| +-- page1.html
| +-- page2.html
| +-- ...
|
+-- /otherstuff/
/ news /文件夹中页面的URL是:
http://www.example.com/news/page1.html
http://www.example.com/news/page2.html
现在,/ news /文件夹中的文件数量正在增长,我想在/ news /中创建新的子文件夹,并在这些新目录中分割文件,但我还想在网址中隐藏子文件夹名称 .
新的文件夹结构将是:
http://www.example.com
|
+-- /news/
| |
| +-- /subfolder1/
| | |
| | +-- page1.html
| |
| +-- /subfolder2/
| | |
| | +-- page2.html
| +-- ...
|
+-- /otherstuff/
但 the urls of the pages have to remain the same :
http://www.example.com/news/page1.html
http://www.example.com/news/page2.html
和 not :
http://www.example.com/news/subfolder1/page1.html
http://www.example.com/news/subfolder2/page2.html
有没有办法在.htaccess中使用重写规则来实现这个结果?
我读过这个问题:How to use mod_Rewrite to check multiple folders for a static file
但是接受的答案对我不起作用 .
提前感谢任何建议 .
1 回答
您可以在/news/.htaccess中使用以下规则:
如果file.html存在于 /news/subfolder/ 中,则会将 /news/file.html 重写为 /news/subfolder/file.html .
如果您的htaccess是root用户,则可以尝试以下操作
如果上面的示例失败,您可以在root或news / .htaccess中尝试: