Remove index.php from URL of Laravel

痞子三分冷 提交于 2019-12-08 04:55:15

问题


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:


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.



来源:https://stackoverflow.com/questions/46380202/remove-index-php-from-url-of-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!