我想使用.htaccess
为所有请求添加public/index.php
我试过这个
RewriteEngine on
RewriteRule ^/(.*)$ /public/index.php/$1 [NC,L]
但它没有改变..
示例:
如果我输入
localhost/project/first
它应该要求
localhost/project/public/index.php/first
我的.htaccess
有什么问题?
答案 0 :(得分:1)
您可以在/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模式中剥离当前目录路径(从而导致斜杠)。