使用.htaccess的Apache 2.4配置别名不起作用

时间:2016-01-08 06:43:46

标签: php apache .htaccess laravel mod-rewrite

我使用php lumen framework,我想像这样设计我的api:

http://somesite.com/api/admin/staffs

这是我的apache vhost和htaccess config

<VirtualHost *:80>
DocumentRoot "D:\webroot"
ServerName dsp-api.dev

Alias /api "D:\webroot\dsp-api\public"
<Directory D:\webroot\dsp-api\public>
    Options +FollowSymlinks +Indexes
    AllowOverride All
    Require all granted
</Directory>

<IfModule mod_rewrite.c>
Options -MultiViews

RewriteEngine On
RewriteBase /api
# Redirect Trailing Slashes...
#RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我确定我的mod_rewrite已打开。似乎.htaccess文件不再起作用了。 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

  

使用路线组 - https://lumen.laravel.com/docs/5.2/routing#route-groups

从vhost&amp;&amp;中删除Alias /api ... Apache重启

恢复公共/ .htaccess

的应用程序/ HTTP / routes.php文件

<?php

$app->get('/', function () use ($app) {
    return $app->version();
});

$app->group(['prefix' => 'api'], function() use($app) {
    $app->get('admin/staffs', function () {
        return '/api/admin/staffs';
    });
    $app->get('admin/users', function () {
        return '/api/admin/users';
    });
});

访问

  • somesite.com
  • somesite.com/api/admin/staffs
  • somesite.com/api/admin/users