Welcome to WebmasterWorld Guest from 54.146.180.94

Forum Moderators: Ocean10000 & incrediBILL & phranque

YYYY.domain1.com/ZZZZ.html redirects to domain2.com/YYYY/ZZZZ.html

   
9:16 am on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do you use apache to redirect from

YYYY.domain1.com/ZZZZ.html

to

www.domain2.com/YYYY/ZZZZ.html

where YYYY and ZZZZ can be anything?

Or, even better, if it can be done, on the second site, using mod_rewrite, have

YYYY.domain2.com/ZZZZ

be the same as

www.domain2.com/cgi-bin/file.cgi?name1=YYYY&name2=ZZZZ

so you redirect from

YYYY.domain1.com/ZZZZ.html

to

YYYY.domain2.com/ZZZZ.html

that, using mod_rewrite, is actually accessing

www.domain2.com/cgi-bin/file.cgi?name1=YYYY&name2=ZZZZ

If it helps, I'm using my own two IP addresses for the domains Nameservers.
8:35 pm on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

Are the two sites on the same server?

Does the rule have to cater for both http and https requests or just http requests?
11:36 pm on Jan 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Same server, just http requests. I haven't tried any code yet, as the only mod_rewrite/redirect that I've ever done is at domain.com/.htaccess that doesn't cover sub-domains.
9:21 am on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Almost got it

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

#Making domain.com/FILE.html work
RewriteRule ^([^.]+)\.html$ cgi-bin/site.cgi?channel=$2&page=$1 [L]

#Making the WHATEVER.domain.com part work.
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.info
RewriteRule ^([^.]+)$ cgi-bin/site.cgi?channel=$1 [L]


http-//CHANNEL.domain.info/PAGE.html

The page name points to the script correctly, but the

CHANNEL.domain.com

part of the URL does get the script, but it isn't pointing to

cgi-bin/site.cgi?channel=ANYTHING

correctly. The channel info works fine at the original URL, but not the sub-domain URL.
8:15 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got it.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^.]+)\.html$ cgi-bin/site.cgi?page=$1 [L]
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) cgi-bin/site.cgi?channel=%2 [NC,QSA]
8:57 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You need to escape all literal periods in all patterns.

Add the [L] flag to every RewriteRule.
6:14 pm on Feb 7, 2011 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



[NC] flag is superfluous with a ".*" pattern, and that pattern is neither necessary nor back-referenced. So, the final rule could be improved:

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+)\.domain\.com [NC]
RewriteCond %2 !^www$ [NC]
RewriteRule ^ cgi-bin/site.cgi?channel=%2 [QSA,L]

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month