我想使用。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模式中剥离当前目录路径(因此,斜杠)。