gpt4 book ai didi

php - 使用 .htaccess 的 Apache 文档根目录

转载 作者:可可西里 更新时间:2023-11-01 01:12:02 24 4
gpt4 key购买 nike

我有一个目录结构

mymvc
|--App
|--Core
|--logs
|--public
|--index.php
|--vendor
|--.htaccess

我想要的是,如果有人点击我的网址 www.example.com/mymvc/ 那么所有请求都必须通过 public->index.php 使用 .htaccess 文件。我无权访问 httpd.conf 文件。

|--public
|--index.php

我希望我的 public 文件夹只能作为文档根访问,请求通过 public 文件夹内的 index.php 文件。没有人可以直接访问 AppCorelogs 等目录。意思是我希望我的公用文件夹是 DOCUMENT ROOT

最佳答案

首先您需要在项目的根目录中创建一个.htaccess 文件。

mymvc/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]

然后,在 public 目录(即 mymvc/public/.htaccess)的 .htaccess 文件中,您需要将 RewriteBase 指令添加到现有代码中,因此它看起来像这样:

mymvc/public/.htaccess

# Remove the question mark from the request but maintain the query string
RewriteEngine On
RewriteBase /mymvc
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

关于php - 使用 .htaccess 的 Apache 文档根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52015013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com