Forum Moderators: phranque

Message Too Old, No Replies

silent redirect

hide browser change

         

WhosAWhata

10:59 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



if i have code like

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site2.com$
RewriteRule (.*) [site2.site1.com...]

how do i make it appear that the browser is actually at site2.com (in the address bar) i've tried adding [L] and [R] to the ends of the rule (i'm not actually sure what they do)

ANY SUGGESTIONS?

jdMorgan

11:33 pm on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That depends on where "site2" and "site1" are hosted -- on the same server? In which subdirectories?

Here's a link to the mod_rewrite documentation [httpd.apache.org]. You can find out all about [R] and [L] flags there.

Jim

WhosAWhata

11:44 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



as you can probably guess, site2.com is a "parked domain" meaning it is just an alias of site1.com by default, however i want to make it seem like its own site. site2.site1.com is a sub-domain i made

my current code works, but it shows the redirect change in the address window


RewriteEngine on
RewriteCond %{HTTP_HOST} ^site2.com$
RewriteRule (.*) [site2.site1.com...] [R]

example:

if i had a site foo.com and a parked domain bar.com
accessing foo.com/whatever would be unaffected,
accessing bar.com would be sent to bar.foo.com
accessing bar.com/whatever would be sent to bar.foo.com/whatever

a little confusing, but i hope this helps

all i need to find out how to do is to redirect the page without it displaying in the address bar

i suppose if this can't be done with just mod_rewrite, there are alternatives using mod_rewrite in addition to PHP, but i would prefer to avoid that

jdMorgan

11:52 pm on Apr 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where in the server file system are the files for site2? I cannot answer your question until you answer mine.

The solution is usually simple.

Jim

WhosAWhata

11:55 pm on Apr 27, 2004 (gmt 0)

10+ Year Member



sorry about that

they are on the same server

from below the root, they look somewhat like this

# root (site1.com)
/home/user/www/www/

# sub-domain (site2.site1.com)
/home/user/www/site2/

the .htaccess file i gave is in
/home/user/www/www/.htaccess

jdMorgan

12:24 am on Apr 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An .htaccess file in /home/user/www/www/.htaccess is not going to be able to silently redirect to a directory above it or beside it in /home/user/www/site2. So you'll need to figure out how a site2 domain request arrives at /home/user/www/www and fix it up before it gets there.

This all depends on how your domains are mapped to your server, so you may want to investigate your DNS records and any "parking" or "pointing" you still have in place. Get rid of all the parking and pointing and point the domains to your IP address using DNS A records only. Then make sure the server configuration does not do an external redirect from site2 to site1. I suspect that's what has caused this mess in the first place -- You've got a parked or pointed domain that is doing a 301/302 redirect. Or possibly, you've got code in /home/user/www/.htaccess that is doing this.

As a matter of fact, if the domains were pointed to the same root directory, you wouldn't even have this problem.

The key to a silent redirect is that the domains must be hosted on the same server in a directory in or below the directory of the code that is doing the redirect. Or the redirect code needs to be in httpd.conf - the server configuration file.

The general form of an internal (silent) redirect is:

RewriteRule ^page1\.html$ /page2.html [L]

No domain name can be specified, otherwise it will be an external (visible) redirect. So, in order to do it, the 'domains' must be in the filesystem below the redirect code.

There are work-arounds involving symlinks and such, but they always turn into spaghetti-balls and cause more problems later. Better to fix the problem by simplifying rather than by complicating...

I hope this makes sense.

Jim

WhosAWhata

12:26 am on Apr 28, 2004 (gmt 0)

10+ Year Member



thanks for you're advise, i'll see what i can do...

pinkopanter

11:09 pm on May 3, 2004 (gmt 0)

10+ Year Member



Hi,

what I did is the following:

Delete the home directory of site1 and make a sim link from site2 home to site1

ln -s /fullpath/site2/html /fullpath/site1/html

WhosAWhata

12:23 am on May 4, 2004 (gmt 0)

10+ Year Member



i can't delter dirs under the root (hosting thing)