【问题标题】:Rewrite urls not working with apache2 and laravel重写 url 不适用于 apache2 和 laravel
【发布时间】:2018-02-26 01:23:37
【问题描述】:

今天我在我的服务器上开始了一个新项目。在我看来,我想我已经正确配置了一切。但是我的.htaccess 似乎无法正常工作或被忽略。我不知道为什么它不起作用。问题是重写 url 会显示 404。

基于 Laravel 5.0 或更高版本的项目我将尝试 Larasocial。 Larasocial 是一个基于 Laravel 5 的社交社区。​​p>

我检查了我的 Vhosts 和 Htaccess 文件,但找不到问题所在。还尝试使用service apache2 restart 重新启动 apache,并查看是否为我的 apache 启用了重写模块。我想一切都应该没问题。

提前感谢您帮助我!

现在这是我的 Vhost 和 Htaccess。

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName integration.julian.droeger.rene-backhaus.de

    ServerAdmin contact@rene-backhaus.de
    DocumentRoot /var/www/html/robot/customers/julian.droeger/integration/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog /home/robot/logs/customers/error.log
    CustomLog /home/robot/logs/customers/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

        # Das folgende erzwingt SSL
    #RewriteEngine On
    #RewriteCond %{HTTPS} off
    #RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
         <Directory /var/www/robot/customers/julian.droeger/integration/public>
          #Options Indexes FollowSymLinks 
          AllowOverride All
      #Require all granted
        </Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =rene-backhaus.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

SSL

<IfModule mod_ssl.c>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName integration.julian.droeger.rene-backhaus.de

    ServerAdmin contact@rene-backhaus.de
    DocumentRoot /var/www/html/robot/customers/julian.droeger/integration/public/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog /home/robot/logs/customers/error.log
    CustomLog /home/robot/logs/customers/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

        # Das folgende erzwingt SSL
    #RewriteEngine On
    #RewriteCond %{HTTPS} off
    #RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
         <Directory /var/www/robot/customers/julian.droeger/integrationi/public>
          #Options Indexes FollowSymLinks
           AllowOverride All
           #Require all granted
    </Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =rene-backhaus.de
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/rene-backhaus.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/rene-backhaus.de/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Htaccess

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

编辑

Apache 错误日志:

[Sun Sep 17 12:42:35.463054 2017] [core:notice] [pid 6843] AH00094: Command line: '/usr/sbin/apache2'
[Sun Sep 17 12:42:42.107113 2017] [mpm_prefork:notice] [pid 6843] AH00171: Graceful restart requested, doing restart
[Sun Sep 17 12:42:42.153704 2017] [mpm_prefork:notice] [pid 6843] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Sun Sep 17 12:42:42.153724 2017] [core:notice] [pid 6843] AH00094: Command line: '/usr/sbin/apache2'
[Sun Sep 17 12:42:44.121750 2017] [mpm_prefork:notice] [pid 6843] AH00171: Graceful restart requested, doing restart
[Sun Sep 17 12:42:44.163280 2017] [mpm_prefork:notice] [pid 6843] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Sun Sep 17 12:42:44.163295 2017] [core:notice] [pid 6843] AH00094: Command line: '/usr/sbin/apache2'
[Sun Sep 17 12:42:46.255223 2017] [mpm_prefork:notice] [pid 6843] AH00171: Graceful restart requested, doing restart
[Sun Sep 17 12:42:46.301081 2017] [mpm_prefork:notice] [pid 6843] AH00163: Apache/2.4.10 (Debian) OpenSSL/1.0.1t configured -- resuming normal operations
[Sun Sep 17 12:42:46.301109 2017] [core:notice] [pid 6843] AH00094: Command line: '/usr/sbin/apache2'

Vhost 访问日志:

79.214.162.134 - - [17/Sep/2017:12:44:02 +0200] "GET /fonts/glyphicons-halflings-regular.woff2 HTTP/1.1" 200 18377 "https://integration.thomas.walczak.rene-backhaus.de/css/libs.css" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:12:44:18 +0200] "GET /feeds HTTP/1.1" 404 725 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:12:44:18 +0200] "GET /favicon.ico HTTP/1.1" 404 593 "https://integration.thomas.walczak.rene-backhaus.de/feeds" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:13:58:26 +0200] "GET / HTTP/1.1" 200 6771 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:13:59:43 +0200] "GET / HTTP/1.1" 200 3664 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:13:59:51 +0200] "GET /feeds HTTP/1.1" 404 725 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:14:00:34 +0200] "GET /feeds HTTP/1.1" 404 725 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:14:00:35 +0200] "GET /feeds HTTP/1.1" 404 587 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:14:01:04 +0200] "GET /feeds HTTP/1.1" 404 725 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"
79.214.162.134 - - [17/Sep/2017:14:01:05 +0200] "GET /feeds HTTP/1.1" 404 587 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36"

虚拟主机错误日志:

[Sat Sep 16 22:57:22.509547 2017] [:error] [pid 30198] [client 217.238.62.18:64841] script '/var/www/html/robot/customers/julian.droeger/integration/status.php' not found or unable to stat
[Sat Sep 16 22:57:23.156553 2017] [:error] [pid 30198] [client 217.238.62.18:64841] script '/var/www/html/robot/customers/julian.droeger/integration/remote.php' not found or unable to stat
[Sat Sep 16 22:57:54.927797 2017] [:error] [pid 30191] [client 217.238.62.18:64850] script '/var/www/html/robot/customers/julian.droeger/integration/status.php' not found or unable to stat
[Sat Sep 16 22:57:55.068064 2017] [:error] [pid 30191] [client 217.238.62.18:64850] script '/var/www/html/robot/customers/julian.droeger/integration/remote.php' not found or unable to stat
[Sat Sep 16 22:58:26.504328 2017] [:error] [pid 30190] [client 217.238.62.18:64852] script '/var/www/html/robot/customers/julian.droeger/integration/status.php' not found or unable to stat
[Sat Sep 16 22:58:26.614808 2017] [:error] [pid 30190] [client 217.238.62.18:64852] script '/var/www/html/robot/customers/julian.droeger/integration/remote.php' not found or unable to stat
[Sat Sep 16 22:58:58.510322 2017] [:error] [pid 30197] [client 217.238.62.18:64853] script '/var/www/html/robot/customers/julian.droeger/integration/status.php' not found or unable to stat
[Sat Sep 16 22:58:58.620842 2017] [:error] [pid 30197] [client 217.238.62.18:64853] script '/var/www/html/robot/customers/julian.droeger/integration/remote.php' not found or unable to stat
[Sat Sep 16 22:59:30.507615 2017] [:error] [pid 30191] [client 217.238.62.18:64863] script '/var/www/html/robot/customers/julian.droeger/integration/status.php' not found or unable to stat
[Sat Sep 16 22:59:30.639602 2017] [:error] [pid 30191] [client 217.238.62.18:64863] script '/var/www/html/robot/customers/julian.droeger/integration/remote.php' not found or unable to stat

【问题讨论】:

  • 您可以显示 Apache 日志显示的错误。

标签: php apache laravel .htaccess


【解决方案1】:

我猜我吸取了教训......

在此article 审查了我的apache.conf 之后。我在那里看到了什么? /var/www 目录未启用 Htaccess!现在解决方案非常简单,我不得不将AllowOverride None 更改为AllowOverride All。 它解决了问题!

但是最后我已经有一个问题了。在这篇文章之前,我认为 Vhost 配置将是重要的配置。因此,在 Vhost 文件中,AllowOverride 为 on All,apache 将采用此配置。为什么 apache2 需要全局 AllowOverride All 配置?谁能解释一下?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 2010-11-11
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    相关资源
    最近更新 更多