2

I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php from URL. My mod_rewrite apache module enabled.

My .htaccess file located in public folder and it contains following code.

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

    Options +FollowSymLinks

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder. But it is not working.

I placed below code in .htaccess file

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

But this not working.

Could anyone help me in this regard ?

1
  • 2
    "I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder." makes me worry. Why did you not just configure your webserver to point to the public folder? Commented Sep 25, 2017 at 9:22

3 Answers 3

3

I found the answer here:

https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/

To summarise, I added the following to the .htaccess file, directly below the existing index.php entry:

RewriteRule ^index.php/(.+) /$1 [R=301,L]
Sign up to request clarification or add additional context in comments.

Comments

2

Reset anything you have changed back to the default.

In your apache virtual host configuration, ensure you have the DocumentRoot correct (it will be something like /var/www/html/laravelproject/public).

You should not need to make any changes to the .htaccess file in the public folder as this handles rewriting the url to remove index.php. However, in some environments, I have had to add

RewriteBase /laravelproject

to the .htaccess in the public folder.

Comments

0

Go to httpd.conf file, search for the line DocumentRoot and change it to where ever your index.php is. For example:

DocumentRoot "C:/xampp/htdocs/myappfolder/public"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.