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

时间:2016-01-28 07:52:10

标签: php apache .htaccess

我正在尝试重写这样的文件夹中的所有请求:

http://www.test.com/banana/banana (或其他)转到 http://www.test.com/public ,但网址仍为 http://www.test.com/banana/banana

我该怎么做?

厂家批号

2 个答案:

答案 0 :(得分:2)

在特定文件夹内,您可以使用此规则创建.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /public/ [L]

答案 1 :(得分:1)

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

.htaccess会将所有请求重写为/public/index.php。仍将提供现有文件和目录。