【问题标题】:Unable to get .htaccess to do 301 redirects correctly in a Laravel app无法让 .htaccess 在 Laravel 应用程序中正确执行 301 重定向
【发布时间】:2019-01-01 22:49:01
【问题描述】:

我遇到了 URL 规范化问题,我想将 https://www.barreau.co/ar 重定向到 https://barreau.co/ar

请注意,以下 .htaccess 代码完美地将 https://www.barreau.co/ 重定向到 https://barreau.co/,但不能使用 Laravel 多语言应用程序添加的 /ar 或 /en。

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

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.barreau\.co\/ar$
RewriteRule ^/?$ "http\:\/\/barreau\.co\/ar" [R=301,L]


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

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

如何使https://www.barreau.co/https://www.barreau.co/ar 都正确重定向到非www URL?

【问题讨论】:

    标签: php laravel .htaccess


    【解决方案1】:

    需要指定 imo 语言环境。

    你可以试试这个吗?

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    

    我在本地环境中使用全新的 Laravel 安装进行了尝试。它工作正常。确保您还启用了 mod_rewrite 并在更改后重新启动您的 apache。

    【讨论】:

      猜你喜欢
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2013-11-04
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多