【问题标题】:How to remove index.php in url ? (laravel 5.3, php 7)如何删除 url 中的 index.php? (laravel 5.3, php 7)
【发布时间】:2017-04-13 03:28:10
【问题描述】:

我的网址是这样的:http://31.220.56.75/mysystem/public/index.php/login

我想删除 index.php,变成这样:http://31.220.56.75/mysystem/public/login

我的 .htaccess :

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

    RewriteEngine On

    # 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}]
</IfModule>

我尝试了一些谷歌教程。但我没有找到解决办法

更新

我尝试像这样更新 .htaccess:

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

没有用

【问题讨论】:

  • 确保 mod_rewrite 已启用。 a2enmod rewrite 然后重新加载apache服务。
  • @Laurent Meganck,我已经运行它了。但是,它不起作用
  • Laravel 的默认 HTACCESS 文件应该已经可以工作了。您是否有可能错误地设置了虚拟主机?
  • @Ronald,设置虚拟主机有什么变化吗?如何设置我的虚拟主机?
  • 在'/etc/apache2/sites-available/00-default.host'中添加虚拟主机

标签: php .htaccess laravel laravel-5.3


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    公用文件夹中的默认.htaccess 应该可以正常工作。检查:original .htaccess

    【讨论】:

    • 也许他的虚拟主机配置没有指向公用文件夹。可能是问题吗?
    • 但即使不是。它应该工作。它不是 .htaccess 它自己
    【解决方案3】:

    按照下面的 .htaccess 文件,希望这会起作用。

    如果您也面临 $_GET 变量的问题,即如果您的 URL index.php 和没有 index.php 都在工作,但发现 $_GET 变量不起作用,那么下面的 .htaccess 代码将为您工作。

    DirectoryIndex index.php
    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
        RewriteCond %{ENV:REDIRECT_STATUS} ^$
        RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule .? - [L]
        RewriteRule .? %{ENV:BASE}/index.php [L]
    
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2019-08-16
      • 2014-07-13
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多