Page 1 of 1

mod_rewrite. subdomain redirecting

Posted: Fri Aug 03, 2007 5:23 am
by Quessir
Hi, all!

I'm trying to make mod_rewrite redirect from e.g. http://username.example.com/profile to http://example.com/user/username/profile.

But it redirect it to http://example.com/user/username/

And e.g http://username.example.com/?id=34&typ=4&zsfa=2 it redirects to http://example.com/user/username?id=34&typ=4&zsfa=2

.htacces:

RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* http://example.com/user/%1 [R=301,L]

Posted: Fri Aug 03, 2007 12:53 pm
by miro_igov
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule (.*) http://example.com/user/%1/profile/$1 [R=301,L]

Posted: Sat Aug 04, 2007 1:23 am
by Quessir
miro_igov wrote:RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule (.*) http://example.com/user/%1/profile/$1 [R=301,L]
You don't understand me. /profile is just example. There maybe various cases

http://username.example.com/profile/
http://username.example.com/news
http://username.example.com/?id=34&type=3, even this (serialized data in async's).

I need to glue everything after username.example.com/* to the end of example.com/user/username/*

Posted: Sat Aug 04, 2007 1:43 am
by Quessir
2 miro_igov: thanks!

I corrected my code with yours a lil. :)

The correct is

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

RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php


But, now if I delete [R=301,L] it wouldn't work.

What directive should I paste here for no redirecting but rewriting.

I mean if I entered

http://username.example.com/profile

it wouldn't redirect me, but understand this as

http://example.com/user/username/profile ?

Posted: Sat Aug 04, 2007 9:18 am
by feyd
mod_rewrite != PHP. Moved to Installation.