douan7529 2019-01-01 14:20
浏览 143
已采纳

无法让.htaccess在Laravel应用程序中正确执行301重定向

I got a URL Canonicalization issue and I want to redirect https://www.barreau.co/ar to https://barreau.co/ar

Please note that the following .htaccess code redirects https://www.barreau.co/ to https://barreau.co/ perfectly, but not with the /ar or /en that the Laravel multilanguage applications add.

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

How can I make both https://www.barreau.co/ and https://www.barreau.co/ar redirect to non-www URLs correctly?

  • 写回答

1条回答 默认 最新

  • dongtang5057 2019-01-01 14:49
    关注

    There's need to specify the locale imo.

    Can you try this?

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

    I tried it in a local environment with a fresh Laravel installation. It works fine. Make sure you also have mod_rewrite enabled and to restart your apache after doing the change.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器