Forum Moderators: phranque

Message Too Old, No Replies

301 question, split content to new domains

         

nipheon

10:36 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



Hello dear apache wizards, I hope you can help me with my question.

I will try to be as precise as possible.

--

Some time ago I got a a domain, I will call it www.example.com.

After a while I made a subdomain called blogs.example.com and opened three blogs there,

blogs.example.com/personalblog
blogs.example.com/businessblog
blogs.example.com/funblog

those were stored on the server in the directory /blogs/(personalblog/ etc.)

now I got me some more domains (which can be pointed on any directory on the server) and I am in the process of letting example.com die (it didnt work out).

now I want to split this content from blogs.example.com to new directories/domains.

both
blogs.example.com/personalblog (/blogs/personalblog/) and
blogs.example.com/businessblog (/blogs/personalblog/)

stay in the same directory on the server, but shall move to the domain

blogs.mynewhomepage.com (/personalblog etc.)

whereas

blogs.example.com/funblog

is on a new directory on the server (moved from /blogs/funblog/ to /funnyblog/) and has its own domain called www.funnierblog.com.

Now the whole domain/directory thing works as planned, I got it all set up with blogger, if I surf to those new domains I get what I want to see, but now I would like to set up an .htaccess file which redirects all incoming requests at blogs.example.com to the new adresses.

If anyone feels up to explaining me this in detail I would be thankful, however I would also be thankful for just some correct lines of code that I copy and paste into a .htaccess file.

Also, an important questions I didn't get answered yet after some googleing : this works for all files, including images, right? because funnyblog got a majority of its hit from the google-imagesearch and I wouldn't like that to stop working.

as I said, I would appreciate any help.

Thanx in advance, Alex

[edited by: jdMorgan at 11:28 pm (utc) on Dec. 14, 2006]
[edit reason] Example.com [/edit]

nipheon

8:20 am on Dec 15, 2006 (gmt 0)

10+ Year Member



Oh well, I managed to do it myself.

I did make an /oldblogs/ folder, placed a .htaccess in each of the three subfolders containing the redirect to the new adress.

Oh, I am proud of myself.

jdMorgan

2:26 pm on Dec 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it working!

It's usually easier to get a response if you show the code you're working on -- Along with the example URL-paths, that serves as a basis for discussion. We ask that you do so in our Apache forum charter [webmasterworld.com]. Also, things get a bit slow in this forum sometimes. Since it involves a specific technology, this forum does not get the traffic levels of something like our Google search forum.

Generally, you can make RewriteRules conditional by testing for the desired/required conditions using RewriteRule and/or RewriteCond patterns. So if this case, if it is desirable to redirect only the "/blogs/personalblog" and "/blogs/businessblog" subdirectories of "blogs.example.com", you could use:


RewriteCond %{HTTP_HOST} ^blogs\.example\.com
RewriteRule ^blogs/((personalblog¦businessblog)/.*)$ http://www.mynewhomepage.com/$1 [R=301,L]

This allows the code to reside in the top-level Web-accessible directory, and is somewhat easier to maintain than several different .htaccess files. It should be noted that using separate files in the subdirectories *is* more efficient, but it is a trade-off between server efficiency and ease of maintenance.

Unless you have additional code that prevents it, this redirect will apply to all URLs in the given domain and URL-paths -- pages, images, scripts, everything.

Replace the broken pipe "¦" character in the code above with a solid pipe character before use; Posting on this forum modifies the pipe character.

Jim

nipheon

2:53 pm on Dec 15, 2006 (gmt 0)

10+ Year Member



the reason that I didnt include any code I was working on is simply that I didn't have any. This is the first time I was working on redirecting, I just used some meta-refresh tags initially, then somewhere stumbled over the info that this is not the way to go, started to read into it and finally landed here. I first thought that it might all be ultra-complicated (hence the post), then I suddenly saw this easy solution of just putting


RewriteEngine On
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://blogs.mynewhomepage.com/$1 [R=301,L]

in each of the directories (the subfolder gets added automatically because the name of the folder stays the same, except for the funblog, but I figured that out too).

I guess there is a more smart/elegant way to do this, but it seems to work.
Also I have to say that I am not a coder at all, but from my old coding days (basic, tp, asm, c) which ended about a decade ago I still know the "concept" of coding and I am capable to edit a script if I can get info on all the commands/variables/expressions used.

Alex