Forum Moderators: phranque
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]
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
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
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...
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]
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
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?