Forum Moderators: phranque
They need 3 redirects, but what they have done, does not work... I can see what they want to do, but they have obviously used the wrong thing?
.
This bit should be OK I think?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^client.com [NC]
RewriteRule ^(.*)$ http://www.client.com/$1 [L,R=301]
.
This bit is obviously wrong?
RewriteCond %{HTTP_HOST} ^host.com/~user/ [NC]
RewriteRule ^(.*)$ http://www.client.com/$1 [L,R=301]
.
RewriteCond %{HTTP_HOST} ^www.host.com/~user/ [NC]
RewriteRule ^(.*)$ http://www.client.com/$1 [L,R=301]
.
I know the blank lines should not be there - they are here to make it more readable.
Not sure I see the goal of the second and third rule with the different host? Are there two sites on the same server, or am I missing something?
They can be combined this way:
RewriteCond %{HTTP_HOST} ^(www\.)?host.com/~user/ [NC]
RewriteRule ^(.*)$ http://www.client.com/$1 [L,R=301]
But, I am not sure what they are for, because it looks like they are for another domain...
Please, let us know what they are trying to do.
Justin
fo example:
RewriteCond %{HTTP_HOST} ^(www\.)?host\.com/ [NC]
RewriteRule ^~user/(.*)$ http://www.client.com/~user/$1 [R=301,L]
Also, I'm assuming that ~user is not a variable here, just to illustrate the point. If it is a variable, then the rule may need to change to copy the 'username' into the new domain's URL.
Jim
The /~user part applies only to the place they are redirecting from. It is replaced by www.domain.com at the destination.
That is www.host.com/~smith/mypage.html becomes www.newwebsite.com/mypage.html for all pages that begin www.host.com/~smith/ only.
.
I assume this might do the job:
RewriteCond %{HTTP_HOST} ^(www\.)?host\.com/ [NC]
RewriteRule ^~user/(.*)$ http://www.client.com/$1 [R=301,L]
Just trying to understand how this stuff really works... (there is only www and non-www at the moment).
mod_rewrite is not that difficult to grasp -- the manual is quite short. Regular-expressions are not too difficult to grasp either, though it takes awhile to get really efficient with them. The two of them in combination can be difficult.
One thing about them that should be pointed out. Just like undocumented source code, it is a lot easier to write than it is to read, and this makes the initial learning curve fairly steep.
Jim