douyinyi7766 2019-02-15 22:53
浏览 32

将.htaccess文件设置为slim

I am having issues redirecting to index.php in my slim app with .htaccess file. Routes work if I add the index.php at the end of the URL

So slimapp.dev/hello/myname gets error

Not Found The requested URL /hello/myname was not found on this server.

while slimapp.dev/index.php/hello/myname works

Here is my .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]

I am using Apache 2 on Ubuntu 18.04

File structure

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>

If I use the php -S localhost:3000 it works as expected but if I use the Apache web server, I most add the index.php to the end of the URL to make it work. Thanks

  • 写回答

1条回答 默认 最新

  • douqin3245 2019-02-16 03:41
    关注

    You are doing wrong.This is quite simple with just two lines of code:

    RewriteEngine On
    RewriteRule ^myname/(.*)$ /$1 [L]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号