0

I set up a local Laravel server for developement and push changes through Git to my production server.

I made a new Laravel project that i pused ok. Then i added php artisan make:auth on my local server and pushed to production but get 404 cant find login (or register). After some work I found out that: www.mySite.com/login can not be found but if I write www.mySite.com/index.php/login it works.

So now I think I have to modify my htaccess to ignore the index.php but I cant get it to work. I tried some suggestions but none seems to work and I don't have a clue why it is not working.

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

    RewriteEngine On
    RewriteBase Test/public/

*    RewriteCond %{THE_REQUEST} /index\.php [NC]           
*    RewriteRule ^(.*?)index\.php$ /$1 [L,R=302, NC, NE]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    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>

The two lines marked with * I tried to add after reading a suggestion here on Stack Overflow (cant find the link now). I also tried htaccess remove index.php from url this suggestion.

Any ideas? Thanks. Edit: My sites-enabled/000-default.conf looks like this:

<VirtualHost *:80>


        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/Test/public

        <Directory /var/www/html/Test/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =nfoscan.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

and my 000-default-le-ssl.conf Looks like this:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that


        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/Test/public



        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mysite.com
</VirtualHost>
</IfModule>

I removed the comments in configs..

I tried to add

<Directory /var/www/html/Test/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>

to my 000-default-le-ssl.conf but it resulted in internal server error..

hybris
  • 21
  • 5

2 Answers2

2

First check if your apache has enabled mod_rewrite you can do it easily by typing

apache2 -M

or even simpler:

a2enmod rewrite

if you had enabled it already you will receive message: "Module rewrite already enabled"

If you haven't then you will receive message: "Enabling module rewrite". You will have to restart apache.

Check if you have in you htaccess line (AllowOverride All)

<Directory /var/www/html/project/>
  Options FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>
Rafael
  • 326
  • 2
  • 6
  • Hi, im very new to apache and apache configs.. I edited my question with the apache config files.. I think the problem is in 000-default-le-ssl.conf but i do not know how to change it to make it work (see my edit). /Thanks :) – hybris Oct 15 '17 at 14:14
  • 1
    Do you have in htaccess: `SSLEngine on` Also you can search in apache logs for errors: `/var/log/apache2/error_log` – Rafael Oct 15 '17 at 14:23
  • In my 000-default-le-ssl.conf I can set DocumentRoot to both /var/www/html or /var/www/html/Test/public and both works fine... but when i mess with only works but gives internal server error ??? – hybris Oct 15 '17 at 18:58
0

Ok so I fixed it. There was some problem in my .htaccess file. I started with removing the .htaccess file in /Test/public and then I didnt get internal server error when messing with in 000-Default-le-ssl.conf file anymore. Then I just copied in another .htaccess file in the directory and it all worked as it should :O

Thanks to all who tried to help me!

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    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>

Posting the working .htaccess file if anyone ever have this problem again :)

hybris
  • 21
  • 5