.htaccess 从站点根目录重定向到公共文件夹,隐藏“公共"在网址? [英] .htaccess redirect from site root to public folder, hiding "public" in URL?
问题描述
下面是我的站点目录结构:
Bellow is my site directory structure:
htdocs/
My-Project/
public/
index.php
css/
img/
js/
src/
config.php
templates/
library/
我不希望任何用户直接访问 src
目录中的任何文件.src
包含我的模板和后端逻辑脚本.
I do not want any direct user access to any files inside the src
directory. src
contains my templating and backend logic scripts.
我想设置我的 .htaccess
以便当用户访问我的网站(根文件夹 My-Project
)时,他们被重定向到 My-项目/公共/index.php
.我希望 URL 在索引页面上看起来像 My-Project.com
.
I want to set up my .htaccess
so that when the user goes to my website (root folder My-Project
), they are redirected to My-Project/public/index.php
. I would like the URL to simply look like My-Project.com
while on the index page.
有什么帮助吗?我很犹豫要不要修改我的 .htaccess 文件,因为我在这里和网上看到了很多关于最佳方法的相互矛盾的建议.
Any help? I am hesitant to modify my .htaccess file as I see a lot of conflicting advice around here and on the net as to the best way to do this.
推荐答案
将此代码放在 /My-Project/.htaccess
中:
RewriteEngine On
RewriteBase /My-Project/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
这篇关于.htaccess 从站点根目录重定向到公共文件夹,隐藏“公共"在网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!