user.domain.com/folder1/ to domain.com/user/

Using a single web hosting account to host multiple sites

user.domain.com/folder1/ to domain.com/user/

Postby grabeuzo » Mon Sep 10, 2007 8:42 am

Hi,
I recently changed my webhoster and had to reorganize part of my website. I don't want to have a subdomain anymore, but this one is still well referenced on search engines, so I have to rewrite the URLs to my new directory structure.

After reading some of the messages here, I didn't find the solution for my specific problem...

This part of the site was hosted in a folder on a subdomain : http://user.domain.com/folder1/
Additionnaly, I had a redirection : when http://user.domain.com was typed, it pointed to http://user.domain.com/folder1/index.php

Now, the site is hosted in http://www.domain.com/user/
I already configured my DNS for user.domain.com , and had no other choice than to make it point to www.domain.com/user/

This is why I am searching for a rule which :
- redirects every request on http://user.domain.com/folder1/ to http://www.domain.com/user/
(for example, http://user.domain.com/folder1/folder2/ ... /file1.jpg shoud redirect to http://www.domain.com/user/folder2/folder3/file1.jpg)

- redirect the requests on http://user.domain.com(/index.php) to http://www.domain.com/user/index.php

Does anyone have an idea of how to do it? Thanks in advance!
grabeuzo
 
Posts: 4
Joined: Mon Sep 10, 2007 8:28 am

Postby richardk » Mon Sep 10, 2007 1:07 pm

Try the following in a .htaccess file in user.domain.com's document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(index\.php)?$   http://www.domain.com/user/index.php [R=301,L]
RewriteRule ^folder1(/(.*))?$ http://www.domain.com/user/$2        [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby grabeuzo » Mon Sep 10, 2007 1:20 pm

Thanks a lot for your code. The last line works perfectly well. You're a modrewrite genius !

However, this line :
Code: Select all
RewriteRule ^(index\.php)?$   http://www.domain.com/user/index.php [R=301,L]

doesn't work, since it results to a loop when trying to access this file (the htaccess is in the same directory as the index.php, since user.domain.com is attributed automatically by my hoster to domain.com/user

The problem is that I'm hosting a site which uses relative links. And if accessed through the adress http://user.domain.com , it can't load the CSS, since it is searching for the /css directory instead of /user/css

But it is not very important. Thanks anyway !
Last edited by grabeuzo on Mon Sep 10, 2007 1:46 pm, edited 1 time in total.
grabeuzo
 
Posts: 4
Joined: Mon Sep 10, 2007 8:28 am

Postby richardk » Mon Sep 10, 2007 1:38 pm

Add
Code: Select all
RewriteCond %{HTTP_HOST} ^user\.domain\.com$ [NC]

above both rules.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby grabeuzo » Mon Sep 10, 2007 1:45 pm

It works perfectly.
Thanks a lot.
If you come to Paris, one day, let me know, I would be glad to offer you a drink !
grabeuzo
 
Posts: 4
Joined: Mon Sep 10, 2007 8:28 am

Postby grabeuzo » Thu Sep 25, 2008 3:46 pm

Hi, it's me again.
I have changed one more the URLs of my site, and I still struggle to deal with mod_rewrite

This, time, I have changed my URLs from http://www.domain.com/example1/index.ph ... a1/blabla2 to http://www.domain.com/example2/index.ph ... a1/blabla2

In both cases, blabla1/blabla2 is the same.

Does anyone know how I could arrange a .htaccess to redirect the URLs of my old "example1" directory to my brand new "example2" ?

Thanks a lot !
grabeuzo
 
Posts: 4
Joined: Mon Sep 10, 2007 8:28 am

Postby richardk » Tue Sep 30, 2008 2:14 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond /post/%{QUERY_STRING} ^/post/|(/post/.+)$
RewriteRule ^example1/index\.php$ /example2/index.php%1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 5 guests

cron