I've two domain names eg www.1st-domain.com
and www.2nd-domain.com
I want to write a Tuckey URL Rewrite rule to redirect any request that goes to www.1st-domain.com
to www.2nd-domain.com
Eg if someone hits www.1st-domain.com/sample
it should be redirected to www.2nd-domain.com/sample
I'm trying something like:
<rule>
<name>Domain Name Check</name>
<condition name="host" operator="equal">www.1st-domain.com</condition>
<from>^(.*)</from>
<to type="redirect">http://www.2nd-domain.com$1</to>
</rule>
It is not working. What am I doing wrong? Please guide.
I'm happy to admit that I made a mistake & the redirection actually works:
<rule>
<name>Domain Name Check</name>
<condition name="host" operator="equal">www.1st-domain.com</condition>
<from>^(.*)</from>
<to type="redirect">http://www.2nd-domain.com$1</to>
</rule>
Didn't work for me; not sure if you were using version 3 or 4 of urlrewrite; anyhow - looked up the 4.0.3 docs ( https://tuckey.org/urlrewrite/manual/4.0/index.html#configuration ) and tweaked your answer a little; this was all that worked for me in the end (tomcat 9.5)
<rule>
<name>Domain Name Check v2</name>
<condition type="server-name" operator="equal">^(www.1st-domain.com)$</condition>
<from>^(.*)</from>
<to type="permanent-redirect">https://www.2nd-domain.com$1</to>
</rule>
Note; the main changing is removing the name="host" attribute and replacing it with type="server-name"
或 4.0 中的另一种方式这将特定于特定规则而不是适用于每个规则
<to qsappend="true"></to>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.