【问题标题】:Laravel remove /index.php/ in URLs and forcing HTTPSLaravel 删除 URL 中的 /index.php/ 并强制使用 HTTPS
【发布时间】:2021-07-05 12:03:37
【问题描述】:

所有这些技巧都正常工作,我被某人黑了,我没有更多的 HTTPS 重定向强制和 /index.php/ 在这里的 URL...

这是我的 public/.htaccess :

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

    RewriteEngine On
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

当我添加时:

RewriteRule ^index.php/(.+) /$1 [R=301,L]

我所有的网址都有一个404 error

你能帮忙吗?

.htaccess: https 工作 URL 中仍然有 /index.php/ (不要删除它):

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

    RewriteEngine On
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /index.php/$1 [L]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

【问题讨论】:

    标签: laravel .htaccess


    【解决方案1】:

    试试这个:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Add below two lines at the end of your .htaccess and before closing IfModule tag
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>
    

    要从 url 中删除 index.php,请尝试:

    在 php.ini 中启用 mod_rewrite

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^index.php/(.+) /$1 [R=301,L]
    

    【讨论】:

    • 感谢@dev,但仍然在 URL 中使用 index.php
    • @LienLien 我已更新代码以从 url 路径中删除 index.php。试试看。
    • 它不起作用。我没有 404 或 500 错误,但我仍然在 URL 中有 /index.php/。我编辑了我的原始帖子,以便您查看我的 htaccess
    • 你启用了 mod_rewrite 吗?
    • 并在启用模式重写后重新启动服务器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 2015-09-09
    • 2020-01-20
    • 2011-10-14
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    相关资源
    最近更新 更多