user3535945
user3535945

Reputation: 241

multiple rewrite for a single url using htaccess

I have a multi blog website in which there are multiple domains. The thing is i need a rewrite rule for the following syntax

XXX.domain.com/{any other things} to www.domain.com/domain/XXX/{any other things}

Also i had written a set of rules for the below one too

^domain/([a-zA-Z0-9]+)/cat/([a-zA-Z0-9]+)$ index.php?domain=$1&cat=$2

So the things is i need to construct a rule which converts domain to path then again process the other things as follows with that.

Upvotes: 0

Views: 98

Answers (3)

Jon Lin
Jon Lin

Reputation: 143856

Before your other rule, you'll need

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.
RewriteCond $1 !^domain/
RewriteRule ^(.*)$ /domain/%1/$1 [L]

Upvotes: 1

Nadav S.
Nadav S.

Reputation: 2459

RewriteRule ^([a-zA-Z0-9\-_]+).domain.com/(.*)$ www.domain.com/$1/$2

([a-zA-Z0-9\-_]+) matches a subdomain.
(.*) matches everything.

This will rewrite whatever.domain.com/anything to www.domain.com/whatever/anything.

Upvotes: 1

nlu
nlu

Reputation: 1963

I hope I understood correctly, that your redirect example has nothing to do with the requirement:

RewriteRule ^([^.]+)\.domain\.com/(.*)$  www.domain.com/domain/$1/$2

[^.]+ captures the subdomain, the rest is selfevident, I hope.

Upvotes: 0

Related Questions