【问题标题】:Apache Virtual Host configuration for PHP routesPHP 路由的 Apache 虚拟主机配置
【发布时间】:2016-10-22 14:35:18
【问题描述】:

我是第一次在 Apache 上进行部署。

这是我的虚拟主机配置:

<VirtualHost *:80>
               DocumentRoot /var/www/myproject.com/web/my-project/Client/app/

            ServerName myproject.com
            ServerAlias www.myproject.com

            ErrorLog /var/log/ispconfig/httpd/myproject.com/error.log

            Alias /error/ "/var/www/myproject.com/web/error/"
            Alias /api/ "/var/www/myproject.com/web/my-project/Server/"
            ErrorDocument 400 /error/400.html
            ErrorDocument 401 /error/401.html
            ErrorDocument 403 /error/403.html
            ErrorDocument 404 /error/404.html
            ErrorDocument 405 /error/405.html
            ErrorDocument 500 /error/500.html
            ErrorDocument 502 /error/502.html
            ErrorDocument 503 /error/503.html

</VirtualHost>

这是我的 .htaccess 文件:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

    RewriteEngine On
    RewriteBase /api
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

我的 HTML 和 Javascript 服务正常。但是 API 调用以 404 响应,说“在此服务器上找不到请求的 URL。

为什么在请求 'my-project/api/countries' 时没有从我的 route.php 中找到 'countries' 路由?

编辑: 我刚刚检查了我的错误日志,它多次显示“AH01630:客户端被服务器配置拒绝”。

【问题讨论】:

    标签: php apache .htaccess laravel-5.2 virtualhost


    【解决方案1】:

    您的重写规则之一需要更正。请参阅下面的正确指令:

     RewriteEngine On
     RewriteBase /api
     # Redirect Trailing Slashes If Not A Folder...
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ $1 [L,R=301]
    

    【讨论】:

    • @starkeen,你的评论是针对我还是威廉格林利?我猜问题出在 .vhost 文件上,而不是 .htaccess 文件上。
    猜你喜欢
    • 2011-05-04
    • 2017-06-14
    • 2012-08-22
    • 2011-10-13
    • 1970-01-01
    • 2018-05-03
    • 2014-11-13
    • 2011-10-14
    相关资源
    最近更新 更多