我在使用.htaccess文件在我的瘦身应用程序中重定向到index.php时出现问题。如果我在URL的末尾添加index.php,则路由有效
所以slimapp.dev/hello/myname
得到错误
Not Found The requested URL /hello/myname was not found on this server.
而slimapp.dev/index.php/hello/myname
工作
这是我的.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]
我在Ubuntu 18.04上使用Apache 2
文件结构
public_html
|_index.php
|_ vendor
|_.htaccess
virtualHost 000-default.conf
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
如果我使用php -S localhost:3000
它按预期工作,但如果我使用Apache Web服务器,我大多数将index.php添加到URL的末尾以使其工作。谢谢
你做错了。这只是两行代码很简单:
RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]