【问题标题】:Apache 2.4 config alias with .htaccess does not work带有 .htaccess 的 Apache 2.4 配置别名不起作用
【发布时间】:2016-01-08 16:27:06
【问题描述】:

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

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

这是我的 apache vhost 和 htaccess 配置

<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 文件似乎不再起作用了。 任何帮助将不胜感激

【问题讨论】:

  • 如果我删除 'alias' 我的配置没问题..我必须这样做,因为我的 angularjsis 在其中。所以不要让我使用流明路由重写。那会与 angularjs 冲突

标签: php apache .htaccess laravel mod-rewrite


【解决方案1】:

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

从 vhost && Apache 重启中移除 Alias /api ...

恢复公共/.htaccess

app/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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2014-10-23
    • 2023-03-21
    • 2021-03-25
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多