301 Redirect Code Writing Instructions

Asked 2 years ago, Updated 2 years ago, 66 views

301 I am trying to find out how to write the redirect code, but I have some questions.
The sample is to redirect http://example.com to http://www.example.com

RewriteEngine on
RewriteCond%{HTTP_HOST}^example\.com$
RewriteRule^(.*)$http://www.example.com/$1 [R=301,L]

appears.

My URL is http://st 〇 ..sakura.ne.jp and http://www.st 〇 ..sakura.ne.jp.
Thank you for your advice.

.htaccess

2022-09-30 19:39

1 Answers

The RewriteCon condition is a regular expression.
RewriteCond 条件Conditional comparison 【 条件Conditional expression 】
%{HTTP_HOST} gets the hostname.
In this case, get st 〇 >.sakura.ne.jp.

^ means beginning and $ means end of sentence.
If you want to compare the exact match, you need to compare the full text, so you can specify a string from the beginning to the end of the sentence.

The characters used in the regular expression must be escaped.
. means any one character in the regular expression, so it works if you say it moves as it is, but
st00-sakura-ne-jp will also be a hit.
So I'll go to \. and escape.

In summary, the description is as follows:

RewriteEngine on
RewriteCond%{HTTP_HOST}^st 00\.sakura\.ne\.jp$
RewriteRule^(.*)$http://www.st 〇 ..sakura.ne.jp/$1 [R=301,L]


2022-09-30 19:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.