dongluolie3487 2015-05-06 23:12
浏览 94

如何从url slim框架设置VirtualHost中删除index.php?

reference image:

enter image description here

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条回答 默认 最新

  • doujuanxun7167 2015-08-18 06:45
    关注

    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 :)

    评论

报告相同问题?