【问题标题】:htaccess redirect 301 https www to non wwwhtaccess 将 301 https www 重定向到非 www
【发布时间】:2017-05-03 22:05:27
【问题描述】:

目前只有主页从 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>

提前致谢

【问题讨论】:

    标签: .htaccess redirect ssl web https


    【解决方案1】:

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

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

    【讨论】:

    • 我正在使用 wordpress,从顶部到 RewriteRule . /index.php [L] 是由 wordpress 自己编写的。你觉得
    • 如果我删除代码会伤害wordpress? (我想是的..)感谢您的帮助
    • @hagaishaul 不,不会的。我知道我在做什么,否则我不会回答这个问题。 wordpress 代码仍在底部。您寻求帮助,我提供了解决方案。
    • 感谢它的正常工作,并为之前的评论感到抱歉
    • @hagaishaul 没问题你能接受答案吗?
    猜你喜欢
    • 2019-08-12
    • 2019-02-04
    • 2018-10-19
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    相关资源
    最近更新 更多