简体   繁体   中英

Rewrite urls not working with apache2 and laravel

Today I started a new project on my server. In my point of view I guess I had configured everything correct. However my .htaccess seems not work correctly or it's ignored. I dont know why it's not working. The problem is that rewrite urls will show an 404.

The project based on Laravel 5.0 or more specified I will be try Larasocial. Larasocial is a social community based on Laravel 5.

I checked up my Vhosts and Htaccess file, but can't find the problem right know. Also try to restart the apache with service apache2 restart and look if rewrite module is enabled for my apache. I guess everything should be okay.

Thanks in advance for helping me!

Now this are my Vhosts and Htaccesss.

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

Edit

Apache error logs:

[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 access logs:

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"

Vhost error log:

[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

Lesseon learned I guess ...

After this article reviewed my apache.conf . And what I see there? Htaccess is not enabled for the /var/www direcotry! Now the solution was quite simple I had to change AllowOverride None to AllowOverride All . It fix the problem!

But and the end I had already a question. Before this article I thourght that the Vhost configuration will be the important configuration. So that AllowOverride is on All in the Vhost file, apache will take this configuration. Why apache2 needs the AllowOverride All configuration globally? Can anyone explaine?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM