.htaccess htaccess使用子文件夹更改子文件夹根目录

nfg76nw0  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(238)

我有一个网站 example.com,其结构如下:

public_html/
    .htaccess
    index.php
    project/
        .htaccess
        public/
            index.php

public_html/.htaccess内容为:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

public_html/project/.htaccess的内容为:

RewriteEngine On
RewriteRule !^public/ /public%{REQUEST_URI} [L]

实际结果

当URL为example.com时,我可以看到public_html/index.php
我无法看到public_html/project/public/index.php当URL是example.com/project时。错误404

预期结果

我希望能够在URL为example.com时看到public_html/index.php
并且我希望在URL为example.com/project时看到public_html/project/public/index.php

其他信息

如果我把public_html/project/.htaccess中的代码放到根目录的htaccess文件中,它就可以工作了。
例如:

public_html/
    .htaccess
    index.php
    project/
        index.php

[公共_html/.htaccess]

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteRule !^project/ /project%{REQUEST_URI} [L]

如果URL是example.com,我就可以看到public_html/project/index.php

dfddblmv

dfddblmv1#

public_html/.htaccess的内容应为:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R,L]

public_html/project/.htaccess的含量应为:

RewriteEngine On

RewriteRule ^$ public/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^public/ public/index.php [L,NC]

请务必从新的浏览器测试它,以避免旧的缓存。

相关问题