Did I make any mistake with .htaccess?

ucdbbs

New Member
Messages
32
Reaction score
0
Points
0
I tried to redirect my subdomains to the directory under public_html.

Nothing works with the following .htaccess.

Code:
RewriteEngine on
RewriteCond %{http_host} .
RewriteCond %{http_host} !^www.mydomain.com [NC]
RewriteCond %{HTTP_HOST} ^(.*).mydomain.com [NC]
RewriteRule ^(.*)$ [URL]http://mydomain.com/%1/$1[/URL] [R=301,L]

Did I miss any point here?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Code:
RewriteCond %{http_host} .
"." matches any one character, so this condition is always true when HTTP_HOST is set. Given the 3rd RewriteCond, this line adds nothing.

Lower-case server variable names may or may not work. The documentation only ever shows them as upper case. Best not to tempt fate.

Code:
RewriteCond %{http_host} !^www.mydomain.com [NC]
RewriteCond %{HTTP_HOST} ^(.*).mydomain.com [NC]
RewriteRule ^(.*)$ [URL]http://mydomain.com/%1/$1[/URL] [R=301,L]
Here you're not redirecting "www.mydomain.com" to "mydomain.com". Is this on purpose? Usually people either force or remove the "www". I can't tell exactly what you want since you weren't very explicit in your post.

Technically, you should be escaping the "." metacharacters in the RewriteCond when you don't want them to function as metacharacters. Since host names have only a few expected values, not escaping the "." shouldn't cause problems.
 

ucdbbs

New Member
Messages
32
Reaction score
0
Points
0
Hi,

I wish to redirect all "subdomains.mydomain.com/blabla..." request except "www.mydomain.com" to
"http://mydomain.com/subdomains/blabla..."

That's why I used "!^www."

So, do you mean I should try
Code:
RewriteCond %{[COLOR="Red"][B]HTTP_HOST[/B][/COLOR]} ^(.*)\.mydomain\.com[COLOR="Red"][B]$[/B][/COLOR] [NC]

Yes. I've tried this on my website hosted at lotus.x10hosting. But it just didn't work.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
What are the actual lines in your .htaccess? What URL are you trying and what is the result?
 
Top