homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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




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

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.

 

g1smd




msg:4259149
 8:35 pm on Jan 27, 2011 (gmt 0)

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?

Jesse_Smith




msg:4259218
 11:36 pm on Jan 27, 2011 (gmt 0)

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.

Jesse_Smith




msg:4259334
 9:21 am on Jan 28, 2011 (gmt 0)

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.

Jesse_Smith




msg:4259671
 8:15 pm on Jan 28, 2011 (gmt 0)

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]

g1smd




msg:4259679
 8:57 pm on Jan 28, 2011 (gmt 0)

You need to escape all literal periods in all patterns.

Add the [L] flag to every RewriteRule.

jdMorgan




msg:4263754
 6:14 pm on Feb 7, 2011 (gmt 0)

[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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved