[英]Apache Document Root using .htaccess
I have a directory structure 我有一个目录结构
mymvc
|--App
|--Core
|--logs
|--public
|--index.php
|--vendor
|--.htaccess
what i want is that if someone hit my url www.example.com/mymvc/
then all the request must go through public->index.php
using .htaccess
file. 我想要的是,如果有人点击我的网址
www.example.com/mymvc/
那么所有请求都必须通过public->index.php
使用.htaccess
文件。 i do not have access to httpd.conf file. 我无法访问httpd.conf文件。
|--public
|--index.php
I want my public
folder to be accessible only as a document root and request pass through index.php file inside public
folder. 我希望我的
public
文件夹是只能作为文档根目录访问,并要求通过内部index.php文件public
文件夹。 No one can access directly App
, Core
, logs
etc. directories. 没有人可以直接访问
App
, Core
, logs
等目录。 Means i want my public folder to be DOCUMENT ROOT
. 意味着我希望我的公共文件夹是
DOCUMENT ROOT
。
First you need to create an .htaccess
file in the root of the project. 首先,您需要在项目的根目录中创建
.htaccess
文件。
mymvc/.htaccess mymvc /的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
Then, in the .htaccess
file in the public
directory (which would be mymvc/public/.htaccess ), you need to add a RewriteBase
directive to the existing code, so it looks like this: 然后,在
public
目录中的.htaccess
文件(可能是mymvc / public / .htaccess )中,需要向现有代码添加RewriteBase
指令,因此它看起来像这样:
mymvc/public/.htaccess mymvc /公/的.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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.