skip to Main Content

I have two laravel 10 projects in the same domain cms and website i access the images and files from cms side that url show domain.com/cms/public/storage/pages/press/root_1683963515doc.pdf here i remove the public from url and the cms domain like domain.com/cms/public/login without move the file from the public folder how we change the url with out public and whic project htacces file is use to change the url here i write in cms htacces file like

RewriteEngine On
RewriteBase /cms/

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

but it not working i put domain.com/cms/login show 404 page, any way to solve this issue?

2

Answers


  1. Just add htaccess on public folder only not any other folder

    I assuming you put project like

    /public
    ├── cms
    │   ├── index.php
    │   └── favicon.ico
    ├── favicon.ico
    ├── storage (link)
    ├── index.php
    └── .htaccess
    

    For main issue domain.com/cms/login can’t access that

    From this above tree you like to use index.php inside cms folder use your one and only htaccess. So only edit you public folder htaccess may be you remove NC it my preference. or may be use Handle Authorization Header.

     <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        </IfModule>
    
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^cms/(.*) /cms/index.php  [NC,L,QSA]
    
        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>
    

    For Stroage use public folder and create symbolic link on public folder and every link is available there if you are store something sensitive

    don’t save on public folder save on like other folder below and access with using controller.

    /storage
    ├── app
    |    ├── public  (this created symbolic link if you use php artisan storage:link)
    |    └── other 
    └── 
    ....
    
    Login or Signup to reply.
  2. Use public folder as Domain Root

    More information about "How to config domain to Laravel app?" – StackOverflow Answer

    The /public appears in the URL if your domain name points to your-project instead of your-project/public. Therefore, you can access your starting index.php with https://example.com/public/index.php.

    # normal directory tree
    server
    ├── your-project
    │   ├── app
    │   ├── routes
    │   ├── public        <--- domain root
    │   │   ├── index.php
    │   │   └── .htaccess
    │   ├── ...
    

    If the root of your domain points to the /your-project/public folder and you can still access its content using the /public address, then either you have incorrectly set up the Route in the /routes/web.php file (perhaps created a group named "public" or added the /public URL part to every route), or your domain is pointing to the /your-project folder incorrectly.

    Set storage to public

    More information about storage folder on Laravel Framework – StackOverflow Answer

    A virtual reference that associates a non-existent path with an existing one. In our example, we can associate the non-existent path public/storage with the physically existing storage/app/public directory.
    How? We have two options for this. Either use the php artisan storage:link command in Laravel specifically designed for this purpose, or manually set it up in the operating system.
    Obviously, the former is the more obvious solution.

    # normal directory tree
    server
    ├── your-project
    │   ├── app
    │   ├── routes
    │   ├── public
    │   │   └── storage    <--- symbolic link (to /server/your-project/storage/app/public)
    │   │   ├── index.php
    │   │   └── .htaccess
    │   ├── storage
    │   │   ├── app
    │   │   │   └── public <--- here can store your files (really folder)
    │   │   ├── framework
    │   │   └── logs
    │   ├── ...
    

    If you create the symbolic link, it will work as expected. For example, you can access the storage/app/public/images/test.png file through a virtual path: public/storage/images/test.png.

    More information about symbolic links

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search