我在我的网络服务器上安装了流明,但我遇到了路由问题
// http://12.345.678.910/
$app->get('/', function() use ($app) {
return "This works";
});
Run Code Online (Sandbox Code Playgroud)
但在第二种情况下,他无法找到目录
// http://12.345.678.910/api
$app->get('/api', function() use ($app) {
return "This dont work";
});
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,我得到标准的404错误.
The requested URL /api was not found on this server.
Run Code Online (Sandbox Code Playgroud)
我使用Apache,Ubuntu,PHP 5.5和Lumen
Bro*_*ary 15
听起来你的URL重写不起作用.如果您index.php在/api它之前添加到URL 有效吗?
例如,如果第二个URL有效,yourdomain.com/api则会成为yourdomain.com/index.php/api,但重写不起作用.
如果您的重写不起作用,但您的.htaccess目录中有该文件public,那么您可能需要在Apache配置中允许覆盖.以下是Ubuntu上Lumen的示例虚拟主机配置.
我已经标记了你需要改变的线条.将第一个和第三个更改为指向public网站目录中的目录.然后将第二行更改为您在网站上使用的域名.
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
AllowOverride All # This line enables .htaccess files
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
您需要重新启动Apache才能使这些设置生效.
启用该.htaccess文件应该可行,但使用.htaccess会减慢您的网站速度.最佳解决方案是将.htaccess文件的内容放在虚拟主机中,然后禁用.htaccess文件.
示例虚拟主机配置如下所示:
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
再次,您需要重新启动Apache才能使这些设置生效.
| 归档时间: |
|
| 查看次数: |
9260 次 |
| 最近记录: |