Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite subdomain to main domain

displaying main domain in address bar but content of subdomain

         

SEOCoder

7:01 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



Hello all,

Looking for some advice.

I have a domain (domain.co.uk) and a shop (shop.domain.co.uk), of which I would like to rewrite the URLs from one to the other. For example I would like the first URL to be whats displayed in the address bar, but the second to be the source:

www.domain.co.uk/product/4/ -> shop.domain.co.uk/product-4.asp

www.domain.co.uk/category/ -> shop.domain.co.uk/category.asp

Is there a .htaccess script that can do this, or something else?

I have tried:

RewriteRule ^category/$ [shop.domain.co.uk...] [L]

but this just redirects the user.

Any advice is very welcome.

Thanks

jdMorgan

10:16 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're confusing URLs and filepaths. You want:

www.domain.co.uk/product/4/ <-- /product-4.asp

With "<--" read as, "provides the content for."

Since you gave an HTTP method and a hostname in your code, that's a 302 redirect. Try just:


RewriteRule ^category/$ /category.asp [L]

If "shop" is not in the same filespace as your main domain, then you'll need to adjust that "category.asp" filepath to point to it. If the shop filespace is not accessible from your main domain -- that is, if it's in a separate virtual host or on another server entirely -- then you'll have to implement a reverse proxy to do this, which can be a pain, as it requires configuration changes to both servers.

Jim

Paul_Winter

10:28 pm on Nov 18, 2009 (gmt 0)

10+ Year Member



Thanks for responding Jim.

The files are not in the same filespace, they're on separate servers. Do you have any idea what I would need to get the hosts to do to perform a reverse proxy?

jdMorgan

11:51 pm on Nov 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to declare a reverse proxy on the "www" server, set it to pass X-Forwarded-For to the "shop" server, then configure the "shop" server to log X-Forwarded-For instead of Remote_Addr if Remote_Addr is the "www" server's IP address and X-Forwarded-For is non-blank.

Also, be aware that the www server will have to send each client request on to the shop server, wait for the shop server's response, and then pass that back to the client. So you now have twice the delay and half the reliability as before.

Jim