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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题