homepage Welcome to WebmasterWorld Guest from 54.166.159.110
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

    
htaccess redirect from subdomain directory
Willi_fl

10+ Year Member



 
Msg#: 390 posted 9:11 pm on Sep 17, 2003 (gmt 0)

Can't get the following accomplished after hours of trying and would appreciate your help:

I have a "maindomain.com" and a parked "parkdomain.net" with it. As per external server set up, visitors of parkdomain.net get to see the content of maindomain.com while their browser keeps showing parkdomain.net. So far so good.

However, any subdomains of the parkdomain are connected with a directory under maindomain, i.e. subdomain.parkdomain.net is maindomain.com/subdomain on the server. subdomain.parkdomain.net cannot internally call anything outside maindomain.com/subdomain (and its subdirectories).

Since my web host isn't helping with changing the configuration, I need some htaccess lines (if possible) which basically rewrite the
subdomain.parkdomain.net/index.php
to maindomain.com/index.php,
so that I can utilize all the stuff on maindomain.com while the visitor's browser keeps showing subdomain.parkdomain.net

Whatever I tried ended either in 500 Internal server error or in getting the stuff from maindomain.com BUT also showing maindomain.com in the browser. Argh!

 

wkitty42

10+ Year Member



 
Msg#: 390 posted 9:17 pm on Sep 17, 2003 (gmt 0)

post examples of what you've tried and we'll see what can be done...

BTW: Welcome to webmasterworld!

oh yes, do not post any actual sites... use mydomain type references and widgitize where approprait ;)

Willi_fl

10+ Year Member



 
Msg#: 390 posted 10:04 pm on Sep 17, 2003 (gmt 0)

Thanks for the welcome!

I have discarded the srcipts resulting in server errors, but here's the last one I tried which does not cause an error but doesn't do what I want either:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ [maindomain.com...] [R=permanent,L]

I have it in the maindomain.com/subdomain directory, and it actually gives me the index.php of maindomain.com after calling sundomain.parkdomain.net/
But after that I also have maindomain.com in the browser.

closed

10+ Year Member



 
Msg#: 390 posted 4:11 am on Sep 18, 2003 (gmt 0)

If you use a RewriteRule like this, the address should still remain on subdomain.parkdomain.net:

RewriteRule ^(.*)$ /directory1/directoryA/$1 [L]

Since it's an internal redirect (a URI, which is generally in the form http://..., isn't used), the address bar doesn't change.

Willi_fl

10+ Year Member



 
Msg#: 390 posted 7:21 pm on Sep 18, 2003 (gmt 0)

I think I see what you're getting at and I'm trying to get the translation of the code in ordinary what-if-then language straight, mentally. I must be making some stupid error, since I can't get it to work.

I should perhaps clarify the directory structure: (the part I have access to):
../wwwroot/maindomain.com/subdomain

So the directory I want to redirect to (maindomain.com) is one level higher than the directory resembling subdomain.parkdomain.net

and restate my goal:
Show index.php of maindomain.com in subdomain.parkdomain.net,
while the server set up is internally translating subdomain.parkdomain.net to maindomain.com/subdomain

You suggest:
RewriteRule ^(.*)$ /directory1/directoryA/$1 [L]

What does /directory1/directoryA translate to in my file structure, and where shall I put it?

Assuming the rule needs to be applied in the subdirectory resembling the subdomain, i.e. before any file gets called from /subdomain, I put the following into /subdomain:

RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ /subdomain ../maindomain.com/$1 [L]
Trying this always gives me 500 internal error. Since I'm not quite sure how to interpret the initial slash in htaccess, I also tried countless variations of it, with the same result.

Assuming the rule needs to be applied before the server had a chance to rout the initial call to maindomain.com/subdomain, I also tried putting it into "maindomain.com", "wwwroot", and "..." (one at a time), like this one in wwwroot:

RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ /maindomain.com/subdomain /maindomain.com/$1 [L]

Same result: 500

This is driving me crazy.

closed

10+ Year Member



 
Msg#: 390 posted 7:34 pm on Sep 18, 2003 (gmt 0)

From [httpd.apache.org ]:

RewriteRule
Syntax: RewriteRule Pattern Substitution

So change the line that says this:

RewriteRule ^(.*)$ /maindomain.com/subdomain /maindomain.com/$1 [L]

to this:

RewriteRule ^(.*)$ /maindomain.com/$1 [L]

Willi_fl

10+ Year Member



 
Msg#: 390 posted 8:16 pm on Sep 18, 2003 (gmt 0)

At least that didn't give me a 500 for the main site :-)

I've put it into wwwroot.

After that, calling subdomain.parkdomain.net still gives me the index.php in maindomain.com/subdomain - and not the expected index.php in maindomain.com

Obviously, the apache server config files must contain something like "if host=subdomain.parkdomain.net then go maindomain.com/subdomain". Can it be, that this overrides any htaccess commands?

Of course, I'm hoping for a "NO" and some way to get it working. Thanks for your assistance!

closed

10+ Year Member



 
Msg#: 390 posted 8:29 pm on Sep 18, 2003 (gmt 0)

Try putting the .htaccess in your maindomain.com directory.

Then this code:

RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ /maindomain.com/subdomain /maindomain.com/$1 [L]

should be:

RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ /$1 [L]

If you're getting the 500 error(s) because of htaccess, it would seem to me that your htaccess commands are not being ignored.

Willi_fl

10+ Year Member



 
Msg#: 390 posted 8:44 pm on Sep 18, 2003 (gmt 0)

You're right, the htaccess is not generally ignored, since it does produce the intended effect written on line 1 below:

RewriteRule ^index\.html$ index.php/$1
RewriteCond %{HTTP_HOST} ^subdomain\.parkdomain\.net
RewriteRule ^(.*)$ /$1 [L]

I have this now in directory maindomain.com, but again it continues to give me the index.php in maindomain.com/subdomain (and as a precaution against missing the big event, I DO always empty the browser's cache before I call the subdomain after uploading a new htaccess).

closed

10+ Year Member



 
Msg#: 390 posted 4:31 am on Sep 19, 2003 (gmt 0)

It seems odd to me that you can access your main site, but you get the 500 for your subdomain. But just to make sure, make a backup copy of your .htaccess in maindomain.com, then put only these two lines in the .htaccess in maindomain.com:

Options +FollowSymLinks
RewriteEngine on

Now try accessing maindomain.com. Do you get the 500 error? If you do, delete the .htaccess in maindomain.com.

Willi_fl

10+ Year Member



 
Msg#: 390 posted 4:00 pm on Sep 23, 2003 (gmt 0)

Was away for a few days, and this morning I've put the following htaccess in maindomain.com:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index\.html$ index.php/$1

This works. What does this tell us, as far as the intended rewrite of the subdomain is concerned?

closed

10+ Year Member



 
Msg#: 390 posted 5:43 pm on Sep 23, 2003 (gmt 0)

The RewriteRule you just posted shouldn't work, unless you've got a directory named index.php. The way I see it, there are two possibilities:
1. You accessed only maindomain.com (instead of maindomain.com/index.html).
2. You can't use .htaccess because it's not allowed on your server.

I'd suggest trying your code by redirecting other files in the maindomain.com directory (i.e. files not starting with index) because Apache's DirectoryIndex directive may be interfering. Instead of the RewriteRule you used, use one of this form:

RewriteRule ^file1\.html$ /file2.html [L]

Willi_fl

10+ Year Member



 
Msg#: 390 posted 6:07 pm on Sep 23, 2003 (gmt 0)

Now you're getting me really confused. I don't have any problem with the redirecting of index.html to index.php. This works just fine.

Instead, picking up on our earlier discussion regarding the rewriting of a subdomain, I implemented the (first) two lines you suggested (to find out if they would cause a server error), and just added the last line, which had always worked.

So, the result is: the two lines you suggested do not casue a 500 error.

But I still have no clue why the other commands we'd tried earlier didn't do a thing, namely rewriting maindomain.com/subdomain as maindomain.com if http_host is subdomain.parkdomain.net

Are we on the same page again?

closed

10+ Year Member



 
Msg#: 390 posted 6:23 pm on Sep 23, 2003 (gmt 0)

Not quite.

When I try a RewriteRule of the form you gave above, I get a 404. Since you didn't get an error, it seems to me that the server did not execute the RewriteRule.

So I'd recommend that you first try my suggestion above, which is to try redirecting other files in the maindomain.com directory. That way, we'll know if .htaccess has any effect at all on your server.

Willi_fl

10+ Year Member



 
Msg#: 390 posted 7:20 pm on Sep 23, 2003 (gmt 0)

I just assume you get a 404 because you do not have a file named index.html AND a file named index.php in your root directory, or am I wrong? I have both, and for some reason I didn't want to delete the index.html and not bother with defining DirectoryIndex in htaccess.

All I can say is the index.php shows correctly when a browser calls either of the following two:
maindomain.com/
maindomain.com/index.html

closed

10+ Year Member



 
Msg#: 390 posted 7:57 pm on Sep 23, 2003 (gmt 0)

Oh, okay. I get it now. It's a php file, so this still works:

RewriteRule ^index\.html$ index.php/$1

although the more correct way of doing it would be:

RewriteRule ^index\.html$ /index.php [L]

If you try using your RewriteRule on an HTML file, then you get the 404.

In that case, I don't know what else could be wrong. It looks like you've got mod_rewrite enabled, and you can use .htaccess. Are you sure you don't have access to your error logs? It would be helpful to know more details about the 500 error you get.

Willi_fl

10+ Year Member



 
Msg#: 390 posted 1:37 pm on Sep 24, 2003 (gmt 0)

I'm going to find out about that today. thank you!

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