mod_rewrite. subdomain redirecting

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
Quessir
Forum Newbie
Posts: 4
Joined: Tue Jul 31, 2007 10:12 am
Location: Almaty, Kazakhstan

mod_rewrite. subdomain redirecting

Post 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]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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]
Quessir
Forum Newbie
Posts: 4
Joined: Tue Jul 31, 2007 10:12 am
Location: Almaty, Kazakhstan

Post 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/*
Quessir
Forum Newbie
Posts: 4
Joined: Tue Jul 31, 2007 10:12 am
Location: Almaty, Kazakhstan

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mod_rewrite != PHP. Moved to Installation.
Post Reply