.htaccess with subfolder other than root

6

I was working with this framework and with this htaccess:

structure

config/
logs/
www/
    app/
    bootstrap/
    public/
        packages/
        .htaccess
        index.php
        ...
    vendor/
    .htaccess
    ...

htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

But I got a shared hosting where I can not change root, and I ended up leaving the structure this way:

config/
logs/
www/
    folder/
        app/
        bootstrap/
        public/
            packages/
            .htaccess
            index.php
            ...
        vendor/
        ...
        .htaccess

In htaccess I left the same and also made several changes, but none worked. How would I do in that case? The page stays white with no error or anything.

UPDATE: my .htaccess folder inside the public folder, looks like this:

<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>
    
asked by anonymous 16.01.2014 / 19:23

2 answers

4

Case 1: Installing Laravel into a subfolder (Symbolic Link)

Following its structure, all you have to do is create a symbolic link in www/folder/index.php pointing to www/folder/public/index.php .

To do this you can: enter the www/folder folder and run the commands:

  

ln -s public / index.php index.php

     

ln -s public / .htaccess .htaccess

And another symbolic link, in www/folder/.htaccess pointing to www/folder/public/.htacess .

Case 2: Installing Laravel in a subfolder (.htaccess)

Add the www / folder folder the following file .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ public/index.php [QSA,L]
</IfModule>

After this change, Laravel will no longer recognize the routes in the same way, since it breaks the url into segments and there is an additional segment called 'folder'

then the routes should follow the model:

Route::get('/folder', function()
{
    return "site.com/folder";
});

Route::get('/folder/login', function()
{
    return "site.com/folder/login";
});

Case 3: Renaming the public folder for www

You do not need to and should not host your application below the public folder for security reasons. If your public folder is named www , what you should do is:

  • Put the contents of the public folder within www .

  • Change the entry public to bootstrap/paths.php .

  • Switch:

    'public' => __DIR__.'/../public',
    

    By:

    'public' => __DIR__.'/../www',
    
        
    16.01.2014 / 19:29
    1

    Based on the information you passed, it is certainly the PHP version :

    Laravel 4 Documentation

      

    The Laravel framework has a few system requirements:

         

    PHP > = 5.3.7
      MCrypt PHP Extension

    Reference - Laravel 4 Doc

    If this is not the case, try the solution below, related to .htaccess and hosting directories .

    Laravel 4 in shared hosting

    Folders required

    I have created the following folders within www (or htdocs / public_html - in some hosts):

    'www/NOME_DO_PROJETO'
    'www/NOME_DO_PROJETO/public'
    

    Link the project domain

    When you enter the client domain in the hosting, refer to the folder you created, but within the public subfolder, in this case: www/NOME_DO_PROJETO/public .

    Ready!

    When you send the files to the server, either by FTP, Git or SVN, put them in the www/NOME_DO_PROJETO folder, and give the appropriate permissions on public and storage .

    With this, everything should work clearly.

    I hope it helps.

    Note: there is no need to change .htaccess, path.php, start.php, etc.     

    17.01.2014 / 16:27