[英]Unable to get .htaccess to do 301 redirects correctly in a Laravel app
I got a URL Canonicalization issue and I want to redirect https://www.barreau.co/ar to https://barreau.co/ar 我遇到了网址规范化问题,我想将https://www.barreau.co/ar重定向到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. 请注意,以下.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]
How can I make both https://www.barreau.co/ and https://www.barreau.co/ar redirect to non-www URLs correctly? 如何才能将https://www.barreau.co/和https://www.barreau.co/ar正确重定向到非www URL?
There's need to specify the locale imo. 需要指定区域设置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. 我在本地环境中使用全新的Laravel安装程序进行了尝试。 It works fine. 工作正常。 Make sure you also have mod_rewrite
enabled and to restart your apache after doing the change. 确保还启用了mod_rewrite
并在进行更改后重新启动apache。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.