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

ApurvaMatey's avatar

Shared hosting url not working.

I am new to laravel. I created an project and run on localhost it give me url "http://localhost/example/index.php". When I link another pages in

' <a href="{{ action('PagesController@about') }}"></a> '

link become "http://localhost/example/index.php/about".

My controller function is

public function about() {
        return view('about');
}

My route is

Route::get('about','PagesController@about');

It executed successfully on localhost.

I uploaded project in live shared hosting server where it give me url "http://sample.com/example/" and when I click on same links given above, the link become "http://sample.com/example/about" and gives error 404 not found. I am not getting index.php on shared hosting links. What should I do? Please help.

0 likes
5 replies
Snapey's avatar

Both your local and your hosted sites are messed up.

You need to consider that /public folder should be the external facing part of your website and everything else is private and not in view.

For local development, your "Document Root" should be /public and in that folder there should be a .htaccess file that includes code to redirect all requests to index.php. Index.php should not be in your URLs

For the shared hosting, often your site will have a folder like

/logs
/public_html
/cgi-bin

you should copy /public from your project (and all children) into /public_html

then you should copy everything else into your root folder.

make sure the storage folder is writeable and you have a .htaccess file in the public_html folder.

ApurvaMatey's avatar

I tried but no use. Does Laravel work on windows shared hosting or not? I have Windows Shared Hosting.

Snapey's avatar

I would not attempt it. It does depend on the web server (IIS or Apache) but you will have nothing but problems.

There are plenty of very cheap options out there for hosting on linux based systems,

ApurvaMatey's avatar

If I enter "sample.com/example" I want my website will load and url will be change as "sample.com/example/public/index.php" automatically.

Everytime whenever I enter "sample.com/example" always url will be shown "sample.com/example/public/index.php".

How should I do this?

Now I have to give complete url "sample.com/example/public/index.php" and when I enter "sample.com/example" server gives 403 Forbidden

Forbidden

You do not have permission to access this document. Web Server at sample.com

How can I give access permission?

Snapey's avatar

and what do you see if you enter sample.com/example/.env ?

Please or to participate in this conversation.