You'll need to use some alias or rewrite to do that in your case, or at least it sounds like that. Or you could create a virtual host with the document root being public.
Remove public/index.php from URL
Hi,
How to remove public/index.php from the URL. I am developing laravel project inside normal php project as sub folder.
Thanks in advance.
The root of your vhost must be the public folder.
For anything like this you will need to tell us what web server software you're using...
Thanks...
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. — Thats it !! :)
@dkarthik If you still need any help getting this sorted, could you please tell us what kind of server you have? You will have installed or be running something like these: Apache, nginx, Homestead, Laragon, XAMPP, LAMP, WAMP, PHP built-in server.
You can add an .htaccess file in the root of your Laravel application, with this content:
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
@shipu Awesome! I'm just starting up with Laravel and found your solution. Just curious if there are any drawbacks with this method?
Here is complete .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /your-folder-name/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
There is already a .htaccess and web.config in the public directory. If you're serving your site correctly then it should just work.
Start by stating what web server you are using and someone can give you a more detailed response.
I had this issue today. I am running my dev server using Mamp Pro on windows 10 and sorted this by doing the following.
Rename the server.php in the your Laravel root folder to index.php.
Sorted.
@Ac1988 And welcome to website exploit city.
@bashy of course this is only for a dev environment if you want to get stuff working. Do you know another way to get this to work on a dev server like Xampp?
For the 999th time, you can install in dev just like production following https://laravel-news.com/subfolder-install (laravel news) and / or http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/
If laravel isn't installed correctly in production there are major security issues.
@bash y of course this is only for a dev environment if you want to get stuff working. Do you know another way to get this to work on a dev server like Xampp?
Yes, just set the document root correctly in your apache element of Xampp so that it points to /public
- http://jonathannicol.com/blog/2012/03/11/configuring-virtualhosts-in-xampp-on-mac/
- http://stackoverflow.com/questions/10157333/xampp-change-document-root
- http://stackoverflow.com/questions/5316185/path-to-root-in-apache-xampp/5316257
- http://blog.mdsohelrana.com/2011/11/01/how-to-change-the-document-root-in-xampp-on-windows/
@Snapey usually pointing one way in development and installing another way on a live server doesn't make sense. In xampp, laravel can be installed above htdocs to duplicate a live server install with the public stuff under htdocs. Technically xampp is no different from a live server.
If people would develop mirrored just like the production will be, they would get it right.
No offense to this poster, but comments like
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder.
are leading people the wrong way.
I wish Jeffrey would do a video of an install on hostgator or godaddy just to demo a shared hosting install, where you ftp up your site.
I have a 5.1 on godaddy, works fine. And yes above public_html, which is like htdocs on godaddy.
In fact @snapey it's from a post you helped me with a long time ago is how it's installed.
@Snapey will give this a shot tonight. Thanks.
I am using Laravel 10. My current .htaccess file in /public folder is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
I got apache error as
[Thu Nov 02 16:03:15.412009 2023] [core:error] [pid 206214:tid 206403] [client 10.64.241.20:55062] AH00124: Request exceeded the limit of 100 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Please advise
@insight Open your own thread if you want help.
Please or to participate in this conversation.