How to remove index.php from url slim framework setting VirtualHost?

天涯浪子 提交于 2019-12-13 01:19:15

问题


reference image:

In this route I have the example:

C:\wamp\www\api

I work with centos in VirtualBox.

In the console of centos I can get into the same folder with this route:

cd /var/www/html/sistemaTareas/api 

Well, in API folder I have:

index.php | .htaccess | Slim

Index.php:

<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoLoader();
$application = new \Slim\Slim();
$application->get('/hello/:firstname/:lastname', function ($firstname,$lastname) {
echo "hola, $firstname $lastname";
});
$application->run();
?>

.htaccess:

RewriteEngine On
RewriteCond  !/src/ [NC]
RewriteRule ^(.*)$ src/$1 [L]

If I put this in Chrome:

http://localhost:8082/sistemaTareas/api/index.php/hello/jean/bergeret

Print this:

hola, jean bergeret

I need print this :

hola, jean bergeret

But with this URL (without index.php):

http://localhost:8082/sistemaTareas/api/hello/jean/bergeret

The VirtualHost in httpd.conf:

#<VirtualHost *:80>
#ServerAdmin me@mysite.com
#DocumentRoot "/var/www/html/sistemaTareas/api"
#ServerName mysite.com
#ServerAlias www.mysite.com

#ErrorLog "logs/mysite.com-error.log"
#CustomLog "logs/mysite.com-access.log" combined

#<Directory "/var/www/html/sistemaTareas/api">
#   AllowOverride All
#   Order allow,deny
#   Allow from all
#</Directory>

For now is commented, but if I uncomment VirtualHost and I use :

http://localhost:8082/sistemaTareas/api/hello/jean/bergeret

print "not found".

I guess the virtualhost is the problem, so how can I configure it to work without index.php? (sorry my english)


回答1:


Configure your VirtualHost like this :

<VirtualHost *:80>
  DocumentRoot "XXX"
  ServerName XXX
  ServerAlias XXX

  <Directory "XXX">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Require all granted
  </Directory>

  ErrorLog "XXX"
</VirtualHost>

And in the base of my project i have an .htaccess file with :

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

Thats's all and it work for me :)



来源:https://stackoverflow.com/questions/30089230/how-to-remove-index-php-from-url-slim-framework-setting-virtualhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!