Forum Moderators: phranque

Message Too Old, No Replies

Folder redirect to domain.

Not sure of exact code...

         

g1smd

11:49 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I only know the basics of .htaccess -- someone emailed me with their problem, and I have no way to test it out or correct it...

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.

jd01

12:24 am on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi g1smd,

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

g1smd

12:32 am on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Want to redirect the old site (on a freehost) at www.host.com/~user/ over to the new location at www.keyword.com on a proper webserver. Site content, pages names, and structure are not changing at all... just a move.

jdMorgan

2:40 am on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/~user is not part of a hostname, it is part of a URL. Therefore, you cannot test for it in the HTTP_HOST test. Move ~user into the URL tested by RewriteRule instead -- that is if it is actually necessary to test the ~user part at all (it won't be necessary if you intend to redirect the entire host.com domain to the new domain).

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

g1smd

12:38 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is for redirecting for one user only, and is for redirecting all of the stuff in their "username" folder (and no-one elses folder), over to the root of the new domain.

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]

jdMorgan

4:36 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, except that I posted an error above. Delete the slash from the end of the host name as well:

RewriteCond %{HTTP_HOST} ^(www\.)?host\.[b]com[/b] [NC]
RewriteRule ^~user/(.*)$ http://www.client.com/$1 [R=301,L]

Jim

g1smd

5:09 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I assume that the "(www\.)?" part literally means that "www." can be either included or completely missing for the matching, but that it cannot be something else (i.e. it matches for domain.com and for www.domain.com but it wouldn't match for test.domain.com).

Just trying to understand how this stuff really works... (there is only www and non-www at the moment).

jd01

9:18 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you are correct...

If you were going to 'match' everything before the first .(dot) optionally, you could use something like this:

([^.]+\.)?

There are a couple of posts in the library that should help if you are looking for basic information...

Justin

g1smd

9:36 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have done all sorts of computer programming and related stuff over the last 25 years or so, but this .htaccess stuff I find to be perversly obscure, esoteric, and just darn right difficult.

jdMorgan

9:46 pm on Nov 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Study regular expressions: It is a simple lexical pattern matching 'language' using 'tokens' of a type that should be familiar to experienced programmers.

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