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

munyamakudzai095's avatar

How to redirect public_html .htaccess to another directory with my laravel app

This is the public_html .htaccess contents

RewriteEngine On
RewriteBase /

RewriteRule ^$ laravel/public/index.php [L]
RewriteRule ^(.*)$ laravel/public/ [L]

but when going to the url i get a 500 error on cpanel

0 likes
16 replies
MehulBawadia's avatar

What is the reason to edit the .htaccess file?

If you are using shared hosting, you can symlink the public_html directory with your project's public directory, and your app will still work.

If you are using cloud or VPS, you need not edit the .htaccess file at all.

What is the error that you get? Check the laravel.log file

munyamakudzai095's avatar

How can I symlink the public_html to the project. Okay checking the logs now.

1 like
Snapey's avatar

delete public_html folder and create a symlink called public_html that points to your project public folder. That works 100%

1 like
munyamakudzai095's avatar

@Snapey Lets say for example I have a primary domain greycode.com and have used its public_html for other purposes but now I want to host a site for that primary domain name

aceventura12's avatar

To redirect your public_html directory to another directory containing your Laravel application, you can modify the .htaccess file in your public_html directory. Here's how you can adjust the contents of your .htaccess file based on what you've provided:

apacheconf Copy code RewriteEngine On RewriteBase /

Redirect the root directly to the Laravel public directory

RewriteRule ^$ /path/to/your/laravel/public/index.php [L]

Redirect all other requests to the Laravel public directory

RewriteRule ^(.)$ /path/to/your/laravel/public/$1 [L] Replace /path/to/your/laravel/public with the actual path to your Laravel application's public directory relative to public_html. The first RewriteRule handles the root URL (^$), and the second rule (^(.)$) handles all other requests, effectively redirecting them to the Laravel application.

Ensure that the .htaccess file is correctly configured and that your server has mod_rewrite enabled. It's also important to test these changes in a development environment before applying them to a live site to ensure everything works as expected.

kokoshneta's avatar

@aceventura12 We already have a ChatGPT-based auto-reply bot here; we don’t need members to act like one as well.

Randy_Johnson's avatar

Hey dude you don't want to do that. What you want to do is SSH into your application. You will have two folders, public_html and app, which contains your laravel application.

From here you want to use a Linux softlink, what that would do it will use the public_html folder and peer into the app/public where it will find your index.php

ln -s /laravel/public public_html

You have to tinker, like either have public_html there or delete public html and run the line, I often find my self pissing around with it but it will work, when it works the ls will display a different colour.

2 likes
munyamakudzai095's avatar

Hi Guys sorry for asking again. Soo I later went to create a symlink file as a php file then added the code below

<?php
$symlinkTarget = 'home/user/example/';
$symlinkName = '/home/user/public_html/mysymlink.php';

// Create the symlink
if (symlink($symlinkTarget, $symlinkName)) {
    echo 'Symlink created successfully.';
} else {
    echo 'Failed to create symlink.';
}
?>

then I changed the contents of the .htaccess to load the symlink

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ /home/user/public_html/mysymlink.php/ [L]

When I go to the domain name I get a blank page Prev was geting a 404 error if I didnt include home/user also was getting an 500 error if I dont include the extention for the mysymlink (.php)

Snapey's avatar

no, a symlink is just a directory entry that you create from the command line. No command line access? This would have to be a really cheap hobby project.

munyamakudzai095's avatar

This is just for learning purposes and the cpanel I was provided with does not have a terminal with it.

Please or to participate in this conversation.