Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.htaccess help 2

Status
Not open for further replies.

vacklin

Programmer
Nov 13, 2001
22
US
Hello all,

First let me say I really didn't know where to post my question since it's about .htaccess. I apoligize in advance and hope someone will move this post to the right spot.

I have a lot of subdomains and I have a .htaccess file setup to point each subdomain to it's correct folder. This is working fine except with one subdomain. The subdomain in question is very simular to another in the site so instead of sending to the correct folder. It sends to the simular one instead.

Here's the subdomain names where the problem is:



My .htaccess file clearly points the subdomain to it's correct folder but no matter what I do the subdomain will only point to
Here's what I am using in my .htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} northeastdallas.domain.com
RewriteCond %{REQUEST_URI} !northeastdallas/
RewriteRule ^$ northeastdallas/$1 [L]

and for the other it's the same:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} eastdallas.domain.com
RewriteCond %{REQUEST_URI} !eastdallas/
RewriteRule ^$ eastdallas/$1 [L]

I would appreciate some help because I have tried everything I can think of and searched the Internet for an answer. I even tried adding this:

RewriteRule ^(.*)$ northeastdallas/$1 [L]

but I understand that the * makes it a wildcard so this doesn't work either.

Thank for your help!
Vickie
 
Vickie,
the apache forum is where you need to post this

HTH
--Paul

cigless ...
 
It does, however, admit to a simple solution:

RewriteCond %{HTTP_HOST} ^northeastdallas.domain.com
RewriteCond %{REQUEST_URI} !^northeastdallas/


and

RewriteCond %{HTTP_HOST} ^eastdallas.domain.com
RewriteCond %{REQUEST_URI} !^eastdallas/
 
MOac,

Wow I didn't know I posted this to the perl forum. I was dancing around the site trying to find where to put it and I guess I was brain fried.

Thank you for your response. I figured out a fix but since you seem to know much more about this than I, I wanted to see what you think. Here's what I did and this worked:

RewriteCond %{HTTP_HOST} eastdallas.domain.com
RewriteCond %{REQUEST_URI} !eastdallas/
RewriteRule ^.*$ eastdallas/ [L]

I removed the () around the .* (that probably made no difference) then I removed the $1

I did this for both and it worked. Do you think this is not correct and that it may cause other problems? Should I leave it as is or try your code?

Thanks, Vickie
 
I'll break the statements down to try to explain:

The first conditional is %{HTTP_HOST} eastdallas.domain.com. This is true if the HTTP_HOST string contains the string eastdallas.domain.com. It doesn't check for equality, only that it's present somewhere - this is why the rule can also match the string northeastdallas.domain.com. This is the reason why you would normally surround the string with ^ and $ - ^ is a marker meaning the beginning of the string, and $ another marker meaning the end of the string. Using these would guarantee that the condition on an exact match. Using an = prefix would also work, as this indicates simple string equality matching.

The second conditional checks to see if the path doesn't contain the string eastdallas/. The ! prefix is used for negation - hence this conitional is true if it doesn't match, rather than if it does. From your code this is apparently intended to be a prefix to the path component, but you don't check to see if it's at the beginning of the string with the ^ marker. This will therefore also match if the string has been earlier rewritten to northeastdallas/.

The rule previously then added eastdallas/ to the beginning of the string. I'm a little puzzled here, because on inspection it would seem that this now replaces the entire string with eastdallas/ instead, which seems wrong. But, if it's working then I'm just being confused.

The (.*) construct in your original code is a two-part construct. .* means the longest possible match of any characters in a string. With no other restrictions, this equates to the entire string. The () surrounding it is used to tell the patern-matcher to remember this string for later substitution. Such strings are numbered in the order that the opening brackets appear in - in this case there is only one string, which can be referred to in the substitution as $1.

The other thing I'm wondering about is the order of the two constructs. Without using the boundary markers ^ and $, these can only work if the rules for northeastdallas come before eastdallas; otherwise the eastdallas match will always succeed, at which point the northeastdallas rules should never get run due to the [L] directive. However, this should have been the case before also, and thus nothing should have changed with your alterations, so I'm a little baffled. Are the rules are seperated by other Apache directives? Depending on the intervening directives, the [L] directive isn't always fully honoured as Apache can consider the rulesets unrelated to one another.

Provided that the solution I offered does work in the way that you intend, I'd recommend using it as it operates in a more rigorous fashion than the one you implement - for example, try it against a fictitious page-construct of which should not get rewritten correctly with your current rules.
 
MOrac,

Thank you for taking the time to explain what each condition and constructs means. I know that took a while and you have taught me exactly what I needed to know. You should consider writing for Apache.org because their information is so difficult to follow.

I see what you are saying. I tried the fictitious page and you are correct, it didn't work.

I have now changed each to the code you provided and it works great with no errors.

I can't tell how much I appreciate your help!

Thanks, Vickie



 
Vickie,

star the man, 4 a start

--Paul

cigless ...
 
Paul,

I didn't know I could star him. I should have read down to the bottom and I would have seen the:

Thank MOrac
for this valuable post!

Thanks Paul, because he deserves the star. I have had some really great help from these forums but I never knew about the star thing. I'll remember it in the future.

Vickie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top