3

ここでこのような質問をいくつか見ましたが、答えがないようです。私はこれを理解できないようです。これが私のコードです:

# enable basic rewriting

RewriteEngine on

# enable symbolic links
Options +FollowSymLinks

# Primary Domain - Force the use of "https"
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

# Primary Domain - Force the use of "www"
RewriteCond %{http_host} ^example.org [nc]
RewriteRule ^(.*)$ https://www.example.org/$1 [r=301,nc]

# Primary Domain - .com to .org
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]

# Primary Domain - .net to .org
RewriteCond %{HTTP_HOST} ^example.net$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.net$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]

そのため、いつでもwww.example.orgリダイレクトhttp://www.example.orgされません。これが私をイライラさせているものです。example.org またはその他のリダイレクトにアクセスすると、機能します。私はこれを間違って設定していますか?

また、「HTTP_HOST」と書いてあるところはそのままでいいのでしょうか?httpホストに置き換えるのと同じように?

4

1 に答える 1

1

wwwAmieと両方を強制したいhttps場合は、www がないことを確認できます。またはリダイレクトされhttpsていないかどうかを確認します。 Onしたがって、いずれにしてもリダイレクトされます。例。

# Primary Domain - Force the use of "https" and www
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L]

mydomain.org を自分のドメインに置き換えます。

次に、このようなhtaccessファイルを作成できます。最後の 2 つのルールを組み合わせて、htaccess ファイルを小さくしました。

# enable basic rewriting
RewriteEngine on

# enable symbolic links
Options +FollowSymLinks

# Primary Domain - Force the use of "https" and www
RewriteCond %{HTTP_HOST} !^www\. [OR] 
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L]

# Primary Domain - .com to .org Or .net to .org
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.(net|com)$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.org/$1 [R=301,L]

また、「HTTP_HOST」と書いてあるところはそのままでいいのでしょうか?httpホストに置き換えるのと同じように?

%{HTTP_HOST}ブラウザーから Http ヘッダーで送信されたホストを含​​む変数です。したがって、誰かがhttp://mydomain.org/somepage.phpその変数%{HTTP_HOST}mydomain.org. あなたはそれを変えません。ルールのように、物事を一致させたり、条件を設定したりするために使用できます。それがあなたの質問に答えることを願っています。

于 2014-02-20T05:41:28.197 に答える