Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

herrPopovic's avatar

Unwanted redirect to project/public folder on VPS

I have installed Laravel on VPS hosting.

It is installed in the /phptube folder on the root of my account.

To avoid using the path for the home page, which is mypage.com/phptube/public, I have created an .htaccess file that looks like:

<IfModule mod_rewrite.c>

 RewriteEngine On
 RewriteBase /phptube/public/

 # Remove public from URL
 RewriteCond %{REQUEST_URI} !^/phptube/public/
 RewriteRule ^(.*)$ /phptube/public/ [L]

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

all work perfectly sve dobro funkcionise i za neku od sledecih adresa mypage.com/en-uk, mypage.com/en-uk/blog, mypage.com/en-uk/blog/category/news, ili mypage.com/en-uk/blog/category/news/post/unlock-the-power-of-programing

but

if I add / (trailing slash an the end of url) at the end of that address, all url addresses are redirected or changed for example

mypage.com/en-uk/ redirect to mypage.com/phptube/public/en-uk

mypage.com/en-uk/blog/ redirect to mypage.com/phptube/public/en-uk/blog

mypage.com/en-uk/blog/category/news/ redirect to mypage.com/en-uk/phptube/public/blog/category/news

mypage.com/en-uk/blog/category/news/post/unlock-the-power-of-programing redirect to mypage.com/en-uk/phptube/public/blog/category/news/post/unlock-the-power-of-programing

How to fix that, or prevent this redirection ?

Thank you

0 likes
13 replies
argethink's avatar

@herrpopovic, can you choose public folder as a your document root.

.httaccess in public folder

<IfModule mod_rewrite.c>

    RewriteBase /

    <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>
herrPopovic's avatar

Do i understend correctly

i must, from public_html/phptube/ all files and folders to move on root (public_html) and then laravel public folder to make as document root ?

argethink's avatar

@herrPopovic

/var/www/app
		 bootstrap
		 config
		 database
		 public  <-- this is the server’s document root
		   index.php
		   robots.txt
		 resources
		 routes
		 storage
		 tests
		 vendor
		 .env
		 composer.json
Snapey's avatar

You have a VPS server. Why can you not just configure it correctly?

herrPopovic's avatar

Do you hawe link, an wich i cann see how to do that ? (first time i work that for VPS) lots i find on google, but ...

jlrdw's avatar

Digital Ocean has some good how to guides on this.

herrPopovic's avatar

@jlrdw At the moment, i am not on Digital Ocean, i am using service from other provider, and i have VPS with WHM/cPanel system.

gych's avatar
  1. Move your laravel project to the document root, one folder up from public_html or www

  2. Move the contents of your public folder inside public_html or www, depends on what your host environment uses.

  3. Change the paths in the index.php to point to your laravel app folder by adding ../laravel_app/ to the paths. For example: ../../laravel_app/vendor/autoload.php'

  4. You can also make a symlink between the public html/www folder and your laravel_app/public folder but first get everything right manually and make sure you understand what's going on. Don't start changing htaccess if not needed.

1 like
herrPopovic's avatar

@gych

for now, all basic functionality i have. As i see, i have problem with photos now (photo from storage folder is not showing ) how that to do ?

Do i ned link to build ? how ? or to change upload folder destination

gych's avatar

@herrPopovic Your storage folder from inside your laravel app is not accessible from the public folder. To solve this you can create a synlink for the storage folder (symlink between /public/storage/your_image_folde & /laravel_app/storage/your_image_folder depending on your current structure)

Do you already have experience with creating symlinks?

herrPopovic's avatar

@gych php artisan storage:link

or

cd /public_html ln -s /laravel_app_folder/storage storage

i have a message that i already hawe this link, but i do not still have a picutres, an i hawe no pictures on webpage

gych's avatar

@herrPopovic If you check the storage folder after creating the symlink do you see the same files in public_html/storage and laravel_app_folder/storage ?

How do you add images to your website can you show me which img source you use?

herrPopovic's avatar

@gych link to all photo is /storage/01HN58E78V16XCQ0DA3BQ7PENA.jpg for example this link show the code in my blade files: <img src="{{ asset('storage/' . $post->thumbnail) }}" class=" ...

in folder /public_html/storage i have one sym link wich lead me to

on first try /laravel_app/storage/ on second try /laravel_app/storage/app/public (where is realy all the fotos)

but, on my web page, i do not photos from this location

Please or to participate in this conversation.