Adam
Adam

Reputation: 29069

Laravel: htaccess is ignored on homestead?

I have created an Laravel app which I locally develop with homestead and which in online on a production server.

I only have a SSL certificate for www.mydomain.com but not for mydomain.com, thats why I force with htaccess a redirect to https://www.*****. I did this by changing the file myproject/public/.htaccess as explained in https://stackoverflow.com/a/13997498/2311074

The redirect works fine on my production server but there is no redirect happening on my local environment with homestead. Why is the redirect ignored on my local environment?

Here is the full .htaccess file:

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

    RewriteEngine On


    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]


</IfModule>

Upvotes: 5

Views: 2209

Answers (2)

Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41400

First SSH into homestead and run command

flip

it will stop nginx and will start apache.

now your .htaccess will work.

PS

The other option is to use type: apache in Homestead.yaml file. But it is not working for me for some reason.

Upvotes: 4

Adam
Adam

Reputation: 2017

I had a similar problem. My production server uses Apache and I need mod_rewrite. Laravel even comes with .htaccess files out of the box!

Here's an elegant solution I found on here.

  1. Add the "type: apache" to my Homestead.yaml file.

    sites:

    map: mylocalapp.com

    to: /home/vagrant/code/public

    type: apache

  2. Reprovision vagrant to use Apache.

    vagrant up --provision

Solved from the answer here on Stack Overflow

Upvotes: 5

Related Questions