如何从url slim框架中删除index.php设置VirtualHost? [英] How to remove index.php from url slim framework setting VirtualHost?
问题描述
参考图片:
在这个路由中,我有一个例子:
\wamp\www\api
我在VirtualBox中使用centos。
在centos控制台中,我可以使用以下路径进入同一个文件夹:
好吧,在API文件夹中我有: p>
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){
echohola,$ firstname $ lastname;
} );
$ application-> run();
?>
.htaccess:
RewriteEngine On
RewriteCond!/ src / [NC]
RewriteRule ^(。*)$ src / $ 1 [L]
pre>
如果我把它放在Chrome中:
http: /localhost:8082/sistemaTareas/api/index.php/hello/jean/bergeret
列印此文件:
hola,jean bergeret
我需要打印:
hola,jean bergeret
但使用此网址(不含index.php):
http:// localhost:8082 / sistemaTareas / api / hello / jean / bergeret
httpd.conf中的VirtualHost:
#< VirtualHost *:80&
#ServerAdmin me@mysite.com
#DocumentRoot/ var / www / html / sistemaTareas / api
#ServerName mysite.com
#ServerAlias www.mysite.com
#ErrorLoglogs / mysite.com-error.log
#CustomLoglogs / mysite.com-access.logcombined
# / var / www / html / sistemaTareas / api>
#AllowOverride All
#订单允许,拒绝
#允许所有
#< / Directory>
如果我取消注释VirtualHost,我使用:
http:// localhost:8082 / sistemaTareas / api / hello / jean / bergeret
打印未找到。
我想virtualhost是问题,那么如何配置它工作没有index.php?
(对不起我的英语)
解决方案像这样配置您的VirtualHost:
< VirtualHost *:80>
DocumentRootXXX
ServerName XXX
ServerAlias XXX
< DirectoryXXX>
选项索引FollowSymLinks MultiViews
AllowOverride所有
需要所有授予
< / Directory>
ErrorLogXXX
< / VirtualHost>
在我的项目的基础中,我有一个.htaccess文件:
RewriteEngine On
RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^ index.php [QSA,L]
这是所有的,它适用于我:)
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)
解决方案 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 :)
这篇关于如何从url slim框架中删除index.php设置VirtualHost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!