Forum Moderators: coopster
www.domain1.com
www.domain2.net
www.website.com
The first two are parked on the third.
I will like that if someone got the site by one of the domains, they get redirected as follows ...
www.domain1.com -> www.website.com/sect1
www.domain2.net -> www.website.com/sect2
www.website.com -> www.website.com - no redirect.
Any ideas please ?
Thanks and much appreciation.
Header("location: [website.com...]
exit;
for the second just change header("location: [website.com...]
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule .? http://www.example.com%{REUQEST_URI} [R=301,L]
Also, if you're worried about search engine rankings, neither will do you any good, because they don't server a proper 301 redirect header. It looks like the first response actually just serves the information to the locations requested, which duplicates your content on 3 domains and is generally considered a VERY bad idea for SEO purposes, the second idea is better, but does not serve a 301 header before the redirect...
At the top of your single index.php:
if(strpos($_SERVER['HTTP_HOST'],'example1.com')!==FALSE ¦¦ strpos($_SERVER['HTTP_HOST'],'example2.net')!==FALSE)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com'.$_SERVER['REQUEST_URI']);
}
Header("location: http://www.example.com/sec1");
This is a very bad idea. While it "works" from the browser, it will do your site tons of damage for ranking.
Also, if you're worried about search engine rankings, neither will do you any good, because they don't server a proper 301 redirect header.
Not sure what you're saying here, the rewrite you posted does issue a 301 permanently moved . . . however, I'd simplify it a little, there may not be a REQUEST_URI.
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</IfModule>
Like normal rexexps, zero or more of "anything" (.*) gets stored in $1.
Documentation [httpd.apache.org] (Scroll to "flags")
You could also modify the server configuration so mod_rewrite is not required, but this is a little deeper dig you may not have access to. In-page redirection is not how you want to do this, it will definately harm your site's indexing.
if(strstr($_SERVER['HTTP_HOST'], 'domain1.com'))
{
ini_set('session.cookie_domain', '.domain1.com');
require_once('sect1/index.hp');
}
else if(strstr($_SERVER['HTTP_HOST'], 'domain2.net'))
{
ini_set('session.cookie_domain', '.domain2.net');
require_once('sect2/index.hp');
}
Not sure what you're saying here
I'm saying neither of the previously posted solutions will probably have the desired effect, so I posted a solution (x 2).
however, I'd simplify it a little, there may not be a REQUEST_URI.
When will a REQUEST_URI not be set?
It will either be / or /something to access the site.
My Mod_Rewrite is much more efficient than what you posted because I'm only comparing a single character or 0 characters and not storing what is already set by default...
All you need to do is match 0 or 1 characters to compare all requested locations to the condition(s) in the ruleset.
In the .htaccess a preceding / is not present for the RewriteRule to be matched, because you are already at /, but %{REQUEST_URI} always starts with the preceding /, even in the .htaccess, so I'm not sure how it could not be set or would be missing, because a URI must be requested to access any part of the site, even the root domain. The REQUEST_URI of http://www.example.com/ is /
I'm saying neither of the previously posted..... When will a REQUEST_URI not be set?
I figure that's what you meant, and yeah, was wondering if you'd catch that. :-P More accurate and what I was thinking (that somehow didn't make it to the fingers), sometimes there will be nothing after /.
My only point was anything after {HTTP_HOST} can go in $1 with (.*).