添加& # 39;公共/ index . php # 39;到所有的请求,而不改变url


Adding 'public/index.php' to all requests without changing url

我想使用。htaccess将public/index.php添加到所有请求

我试过了

RewriteEngine on
RewriteRule ^/(.*)$ /public/index.php/$1 [NC,L]

但它没有改变…

示例:

如果我输入

localhost/project/first

应该请求

localhost/project/public/index.php/first

我的.htaccess有什么问题?

您可以在/project/.htaccess中使用这样的规则:

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]

这是/project/public/.htaccess:

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /project/public/
RewriteRule index'.php$ - [L,NC]
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [L,R=301,NE]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond是为了避免对真实的文件和目录进行重写。在。htaccess的RewriteRule模式中不应该有任何前导斜杠。.htaccess是每目录指令,Apache从RewriteRule URI模式中剥离当前目录路径(因此,斜杠)。