gpt4 book ai didi

.htaccess - htaccess 将 301 https www 重定向到非 www

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:47 24 4
gpt4 key购买 nike

目前只有主页从 www.example.com 和 example.com 重定向到 https://example.com

我尝试重定向:

1. http://www.example.com/otherpages to https://example.com/otherpages 
2. http://example.com/otherpages to https://example.com/otherpages
3. https://www.example.com to https://example.com
3. https://www.example.com/otherpages to https://example.com/otherpages

尝试使用一些以前的问题,但无法弄清楚。

.htaccess 中的当前状态是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.my\-domain\.com [NC]
RewriteRule ^(.*)$ http://my-domain/$1 [L,R=301]
</IfModule>

提前致谢

最佳答案

您不需要所有代码来满足您想要的条件。用这个替换你所有的代码并更改为你的域。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

关于.htaccess - htaccess 将 301 https www 重定向到非 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41212690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com