0

I moved my Laravel application from the development localhost to an internet production subdomain. On localhost everything works. But when I move app to subdomain it seems .htaccess can not handle redirects correctly. When i type to browser sub.mydomain.com it redirect to sub.mydomain.com/public. Main webpage renders. But when i go to login page it returns 500 error. route is now sub.mydomain.com/public/login

It works only when i manualy type sub.mydomain.com/public/index.php/login

I do not know why is this happens, but on localhost it works fine.

My root .htaccess:

RewriteEngine on

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

RewriteCond %{REQUEST_URI} !^public

RewriteRule ^(.*)$ public/$1 [L]

And my /public .htaccess

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Can you advise me how to properly configure htaccess to make it work properly?

Sahasrar
  • 3
  • 1
  • 3

1 Answers1

0

This is my .htaccess configuration I'm using inside public folder Options -MultiViews

RewriteEngine On

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

Redirection from http to https :

<VirtualHost *:80>
  ServerName yourdomain.com
  ServerAlias www.yourdomain.com
 
  DocumentRoot /var/www/html/public

  Redirect Permanent / https://yourdomain.com/

  ....
  ....

</VirtualHost>

<VirtualHost *:443>
  ServerName yourdomain.com
  ServerAlias www.yourdomain.com
 
  DocumentRoot /var/www/html/public

  Redirect permanent http://www.yourdomain.com/ https://yourdomain.com

  ....
  ....

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

Thanks!