将.htaccess文件设置为slim

问题描述 投票:-1回答:1

我在使用.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的末尾以使其工作。谢谢

php slim
1个回答
0
投票

你做错了。这只是两行代码很简单:

RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]
© www.soinside.com 2019 - 2024. All rights reserved.