本文介绍了从domain.com重定向(301)到www.domain.com,同时也迫使.htaccess的HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,这是我最初时会被重定向任何domain.net或www.domain.net到www.domain.com(使用SSL)。

  RewriteEngine叙述上
的RewriteCond%{} SERVER_PORT!443
重写规则^ * $ HTTPS://%{SERVER_NAME}%{REQUEST_URI} [R,L]
的RewriteCond%{HTTP_HOST} ^域\ .NET $ [OR]
的RewriteCond%{HTTP_HOST} ^ WWW \。域\ .NET $
重写规则^ / $?HTTP \:\ / \ /域\ .COM[R = 301,L]
 

现在,我想迫使所有这些条件,报告301(对于搜索引擎而言):domain.netwww.domain.netdomain.com

和强制所有条件:www.domain.com使用S​​SL(甚至有人打字 http://www.domain.com 应达到的)。

这是否有意义吗?这是我有这么远,我认为会的工作,但我不知道如何在301部件添加...

  RewriteEngine叙述上
的RewriteCond%{} SERVER_PORT!443
重写规则^ * $ HTTPS://%{SERVER_NAME}%{REQUEST_URI} [R,L]
的RewriteCond%{HTTP_HOST} ^域\ .NET $ [OR]
的RewriteCond%{HTTP_HOST} ^域\ .COM $ [OR]
的RewriteCond%{HTTP_HOST} ^ WWW \。域\ .NET $
重写规则^ / $?HTTP \:\ / \ /域\ .COM[R = 301,L]
 

解决方案

你说你只想www.domain.com使用,但是你code说,你只需要使用domain.com。无论如何,这应该做的伎俩:

  RewriteEngine叙述上
的RewriteBase /

#比www.domain.com其他任何域重定向到www.domain.com
的RewriteCond%{HTTP_HOST}!^ WWW \。域\ .COM $ [NC]
重写规则^(。*)$ https://www.domain.com/$1 [L,R = 301]

在www.domain.com#力HTTPS
的RewriteCond%{HTTPS} ^关闭
重写规则^(。*)$ https://www.domain.com/$1 [L,R = 301]
 

Ok, so this is what I have originally , which redirects any domain.net or www.domain.net to www.domain.com (with SSL).

RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^domain\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.net$
RewriteRule ^/?$ "http\:\/\/domain\.com" [R=301,L]

Now, I want to force all of these conditions to report 301 to (for search engine purposes):domain.netwww.domain.netdomain.com

and force all conditions to:www.domain.com WITH SSL (even somebody typing http://www.domain.com should reach https://www.domain.com).

Does that make sense? Here's what I've got so far, which I think will work, but I don't know how to add in the 301 part...

RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^domain\.net$ [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.net$
RewriteRule ^/?$ "http\:\/\/domain\.com" [R=301,L]
解决方案

You say you want to use only www.domain.com, but you code says you only want to use domain.com. Anyway, this should do the trick:

RewriteEngine On
RewriteBase /

# redirect any domain other than www.domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

# force https on www.domain.com
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

这篇关于从domain.com重定向(301)到www.domain.com,同时也迫使.htaccess的HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:08