Question

I've two domain names e.g. 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

E.g. 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.

Was it helpful?

Solution

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>

OTHER TIPS

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"

or Another way in 4.0 This willbe specific to the particular rule instead of applying to every rule

<to qsappend="true"></to>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top