Forum Moderators: phranque

Message Too Old, No Replies

Rewrite with from one domain to another w/ String conditions

also need help uploading the .htaccess file

         

nzap

11:19 am on Oct 17, 2007 (gmt 0)

10+ Year Member



Any help would be greatly appreciated.

I am trying to create a .htaccess file that will allow me to switch the following URL:

domainX.com/Merchant2/merchant.mvc?

to

domainY.com/Merchant2/merchant.mvc?

Anything that has that string in it I would like forward, but anything that does not I would like to remain the same.

So for example,

domainX.com/Merchant2/merchant.mvc?storeurl&sample1=432

to

domainY.com/Merchant2/merchant.mvc?storeurl&sample1=432

But if someone simply goes to: domainX.com or domainX.com/url.html it should stay at domainX.

Another issue I'm having is when I save .htaccess file in notepad, it does not convert correctly. I can't even upload it correctly to my server. Do I need a special editor or is there a special way to save it?

My hosting company gave me the below .htaccess file, but I don't know if it works and it redirects everything ... rather than just the particular strings I would like redirected:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} www.domainX.com RewriteRule (.*) [domainY.com...] [R=301,L]

Also would like this to work for both "www" and without "www"

* Any help would be greatly appreciated!

jdMorgan

4:24 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make the "www." optional, escape the literal periods, and test the query string for not-blank:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainX\.com
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) http://www.domainY.com [R=301,L]

Jim

g1smd

6:45 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would add a slash to the last line:

RewriteRule (.*) http://www.domainY.com/ [R=301,L]

nzap

9:50 am on Oct 23, 2007 (gmt 0)

10+ Year Member



Hi,

I haven't been able to get the file to work ...

Not sure why.

I did:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainX\.com
RewriteCond %{Merchant2/merchant.mvc*} .
RewriteRule (.*) [domainY.com...] [R=301,L]

I also tried:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainX\.com
RewriteCond %{http://domainX.com/Merchant2/merchant.mvc*} .
RewriteRule (.*) [domainY.com...] [R=301,L]

I tried multiple other variations of the above and it does not do anything. What am I doing wrong?

The query string I am trying to effect is "Merchant2/merchant.mvc" -- any time this string is in the domainX URL, I would like the URL changed to DomainY but keep all the rest of the URL string the same.

Should I be putting astrics in there somewhere in the query? I even tried that. Can't get it to work.

Help is greatly appreciated!

jdMorgan

1:00 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either of the following will likely work better. I should caution you against 'guessing' about server config code; The chances of success without careful review of the relevant Apache documents are practically zero.

Code for use in domainX/.htaccess:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainX\.com
RewriteRule ^Merchant2/merchant\.mvc$ http://www.domainY.com/Merchant2/merchant.mvc [R=301,L]

Code for use in domainX/Merchant2/.htaccess:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domainX\.com
RewriteRule ^merchant\.mvc$ http://www.domainY.com/Merchant2/merchant.mvc [R=301,L]

In both examples, the query string will be passed through the rule unchanged.

Terminology: Note that "Merchant2/merchant.mvc" is the local URL-path, and "storeurl&sample1=432" is a query string. The "?" delimits the URL-path from the query string, and is part of neither.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

nzap

3:53 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



Hi, Jim,

Thank you for your help. That did it! This is instrumental in helping us move our domain to our new one.

All the best,
Afshin