简体   繁体   English

使用 .htaccess 文件将所有请求重写到文件夹

[英]Rewrite ALL requests to a folder with .htaccess file

I'm trying to rewrite all requests in a folder like this:我正在尝试重写文件夹中的所有请求,如下所示:

https://www.test.com/banana/apple (or whatever) goes to https://www.test.com/public but in the url is still https://www.test.com/banana/apple . https://www.test.com/banana/apple (或其他)转到https://www.test.com/public但在 url 中仍然是https://www.test.com/banana/apple

How can I do this?我怎样才能做到这一点?

Inside that specific folder you can create a .htaccess with this rule:在该特定文件夹中,您可以使用以下规则创建一个 .htaccess:

RewriteEngine On

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

This .htaccess will rewrite all requests to /public/index.php .这个.htaccess会将所有请求重写到/public/index.php Existing files and directories will still be served.仍将提供现有文件和目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM