How Can I Remove public index php in the URL Generated Laravel

0 votes

I need to remove index.php or public/index.php from the generated URL in Laravel; commonly path is localhost/public/index.php/someWordForRoute, It should be something like localhost/someWordForRoute.

.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes.
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php[L]

app/config/app.php

'url' => 'http://localhost',

How can I change that?

Aug 10, 2020 in Laravel by kartik
• 37,520 points
13,484 views

1 answer to this question.

0 votes

Hello @kartik,

If it isn't already there, create an .htaccess file in the Laravel root directory. Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder)

Edit the .htaccess file so that it contains the following code:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Now you should be able to access the website without the "/public/index.php/" part.

Hope it helps!!

Thank You!!

answered Aug 10, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How can I serve a single HTML page from the Laravel public folder without having to use the .html extension?

Hello @kartik, You may rename the test folder ...READ MORE

answered Nov 12, 2020 in Laravel by Niroj
• 82,840 points
5,602 views
0 votes
1 answer

How can I find the current language in a Laravel view?

Hello @kartik, The cleanest way to know the ...READ MORE

answered Dec 3, 2020 in Laravel by Niroj
• 82,840 points
4,520 views
0 votes
1 answer

How can I change variables in the .env file dynamically in Laravel?

Hii, You can created the function below: public static ...READ MORE

answered Dec 4, 2020 in Laravel by Niroj
• 82,840 points
4,292 views
0 votes
1 answer

How can I obtain a list of all files in a public folder in laravel?

You could create another disk for Storage ...READ MORE

answered Dec 8, 2020 in Laravel by Niroj
• 82,840 points
3,984 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,994 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,685 views
0 votes
1 answer

How can I echo the version of the current Laravel version in php using the view?

Hello @kartik, This is the way how to ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,840 points
1,198 views
0 votes
1 answer

How can I clear the cache in laravel using command line?

Hello @kartik, cache:clear artisan command does calls flush function on current ...READ MORE

answered Oct 28, 2020 in Laravel by Niroj
• 82,840 points
2,102 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP