Forum Moderators: phranque

Message Too Old, No Replies

Redirect silently "parked (or pointed) domains" to subdirs

         

nacho84

3:32 pm on May 17, 2004 (gmt 0)

10+ Year Member



In other post (refer to "Trying virtual host in .htaccess") I was asking how to redirect silently if someone access a p1-domain.com to domain.com/p1-domain.com

With silently I mean that in the navigation bar of the browser it doesn't change to [domain.com...]

I was using the rules below but working as external redirection (because of the [R] option) but without the [R] I get a 500 internal error.


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?p1-domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/p1-domain/$1 [R=302,L]

The only way I've gotten the redirect to work is with


RewriteCond %{HTTP_HOST} ^(www\.)?p1-doamin\.com$ [NC]
RewriteRule ^/(.*)$ http://domain.com/p1-domain/$1 [L]

(note the slash in the RewriteRule pattern)

so to access the site if I write in the browser
[p1-domain.com...]
I get the content of
[domain.com...]

but if I write
[p1-domain.com...]
I get the right thing (silently the content under [domain.com...]

It seems to be that something it's bothering the RewriteRule to match with ^(.*)$
In other words, the matching pattern cant start with a optional character (I've also tried ^/?(.+)$ )

Anyone could help?

Thanks!
Nacho,
Argentina

jdMorgan

3:57 pm on May 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nacho,

Review the mod_rewrite documentation and the examples in the Apache URL Rewriting Guide -- Your "slash problem" is caused by the slight difference in the URL "seen" by RewriteRule in httpd.conf and .htaccess contexts.

For example, in httpd.conf, you might use:

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

But in .htaccess, it would be:

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

Also, the following thread might be useful to you if you have a large number of parked domains: [webmasterworld.com...]
Note that the discussion and code posted there deals with the subdomain part of the URL, but you could modify it to use the domain part.

Jim

nacho84

9:49 pm on May 17, 2004 (gmt 0)

10+ Year Member



Yes, that's true. There are differences with the .htaccess and the httpd.conf.
But I don't have access to the httpd.conf

And in the .htaccess I've got an error if I use ^(*.)$
without the "/".
I'm still looking for a solution in the other posts.
I've also tried for example ^a(.*)$ and it works...
(I was saying it seems to be a problem to the mod_rewrite to understand the beginnig with an optional character).

thanks, Jim..

Nacho
PD: still looking...

jdMorgan

10:34 pm on May 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what I've used in .htaccess for the same purpose:

Options +FollowSymLinks
RewriteEngine on
# Get the requested domain name in %2, first part of URL-path in %4
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^(www\.)?([^.]+)\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when domain not equal to first part of path (prevent mod_rewrite recursion)
RewriteCond %2<>%4 !^(.*)<>\1$ [NC]
# Domain name now in %1 -- Silently rewrite any request for http://www.p1-domain.com/file to http://www.p1-domain.com/p1-domain/file
# (Since domain.com and p1-domain.com are both resolved to this server, they are equivalent.)
RewriteRule (.*) /%1/$1 [L]

Step one: If http://www.p1-domain.com/file.html is requested, %2 will be "p1-domain" and %4 will be "file.html"
Step two: Check to be sure that %2 is not equal to %4. (They will be equal if www.p1-domain.com/p1-domain/file.html is requested, either manually or because of an internal subrequest)
Step three: If the subdirectory name was not already present in the requested URL-path, do the rewrite.

If this code is not clear, see the thread I cited above.

If it doesn't work, than maybe you've got some interaction going on with the server config; UseCanonicalName on often causes missing-trailing-slash problems, and mod_dir should also be loaded and enabled (ask your host). Also, it's possible there is an error in httpd.conf that is messing up your code -- it does happen.

Jim

nacho84

5:53 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



All this it was very strange, but after of night without sleeping, I got it:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.ar$ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule!^any_thign_can_be_here/(.*)$ site/%1 [L]

this is working well till now....

thanks to all...

Nacho

joyryde

1:01 am on Sep 17, 2005 (gmt 0)

10+ Year Member



Hi - My terrible hosting company has changed the "add-on" domain fee (to have multiple sites hosted under one hosting account) from $10 per domain for the life of the domain, to $2.95 a month per domain.
What has now happened is that unless you pay them $2.95 a month, all domains that used to be active on a single hosting account, now point to the master domain of that account rather than to each of their own sub-folders like they did before.

I need a way to direct a domain sto a specific folder under my master domain using .htaccess so that users don't see the master domain for all domains, they see each specific website.

Is this possible, and can you give an example?