Apache rewrite for Laravel /public

后端 未结 2 1430
臣服心动
臣服心动 2020-12-11 09:48

I am sorry about this, but my htdocs root is wrong and I can\'t change that. So I have to make it work in the /public folder.

I use the normal Laravel .

相关标签:
2条回答
  • 2020-12-11 10:21

    I use the 3 solution of this post and works fine:

    http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258

    Solution 1 - Alternate installation path with symlink.

    This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.

    For example:

    Install your application to /home/applications/mysite.com

    Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs

    Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs

    Solution 2 - .htaccess with mod_rewrite

    This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.

    Step 1. Place Laravel in your document root folder.

    Step 2. Place the following .htaccess file in your document root folder.

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

    Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments

    Solution 3 - merge the public folder into the installation root

    This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.

    Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:

    require '../paths.php';
    

    to

    require 'paths.php';
    

    Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.

    Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.

    0 讨论(0)
  • 2020-12-11 10:25

    I solved it partly. If I have a .htaccess in the root instead of /public with

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /public/index.php/$1 [L]
    

    I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.

    0 讨论(0)
提交回复
热议问题