xaddict
xaddict

Reputation: 1328

.htaccess subdomain redirect with variables

I'm looking for a way to have an url like

-cbbbc.example.com

redirect to

example.com/something/maybesomethingelse/-cbbbc

So $.example.com should redirect to example.com/1/2/$

Normally you would just take everything before example.com and redirect it to the other place. But I do have admin.example.com and otherstuff.example.com that I don't want to redirect, because they already have other redirects in place.

the variable before example.com could be anything, the only rule it has is it starts with a certain character "-" in this case, has a specific number of characters (5 in this case) and is never one of the predetermined names (like for example admin, logout, login, etc.)

Is there a way to make a htaccess rule that takes all of these criteria and redirects according to them?

Plus: A bonus would be if -cbbbc.example.com could redirect to example.com/1/2/cbbbc, without the dash. Is this possible?

Thanks!

Upvotes: 0

Views: 582

Answers (1)

undone
undone

Reputation: 7888

RewriteCond %{HTTP_HOST}   !^admin\.example.com$ [OR]
RewriteCond %{HTTP_HOST}   !^login\.example.com$ [OR]
RewriteCond %{HTTP_HOST}   !^logout\.example.com$
RewriteCond %{HTTP_HOST}   -(.{5})\.example.com
RewriteRule (.*)  http://example.com/something/maybesomethingelse/-%1

I did not test it but I think it works!let me know if not!

Upvotes: 2

Related Questions