Index.php for Website子文件夹

时间:2018-01-24 03:54:26

标签: php .htaccess

我的网站有index.php个文件。一切都很好。

我刚创建了一个新文件夹,我想要一些不同的页面。该目录结构如下:

root
    - index.php
    - .htaccess

我希望它看起来像:

root
    - index.php
    - .htaccess
    - <folder>
        - <index.php for folder>
        - customer.php

这可能吗?为子文件夹设置单独的index.php文件?我相信它是,等等......

理想情况下,网址(.htaccess删除.php等会成为:

www.mywebsite.com/folder

将通过

访问客户文件

www.mywebsite.com/folder/customer

这可能吗?或者我特别需要写 www.mywebsite.com/folder/index

如果需要,我可以向.htaccess添加<folder>

另一种可能的解决方案:

同时拥有<folder>.php文件以及名为<folder>的目录,然后索引页面转到php文件,而任何文件更深入到<folder>目录内的文件。唯一的问题是修改。htaccess以便在转到www.mywebsite.com/<folder>

时知道转到php文件而不是目录

<小时/> 我的.htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteEngine On

由于

1 个答案:

答案 0 :(得分:0)

我决定只手动强制页面显示文件与目录,感谢this stack overflow post

# Manually re-route <folder>/ requests to folder.php
RewriteCond %{REQUEST_FILENAME} <folder>/$
RewriteRule ^(.*)/$ $1 
相关问题