views:

276

answers:

4

This is a continuation of: http://stackoverflow.com/questions/623161/help-with-basic-htaccess-modrewrite

I was told to use

RewriteRule ^error/(.*) index.php?error=$1 [L]
RewriteRule ^file/(.*) index.php?file=$1 [L]

and

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]

before each, but it dosn't really help me specifically.

I am using a wildcard sub-domain how can I make this condition:

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]

dynamic, like if it is any subdomain (except www.) so what do I need to change.

A: 

I'm not sure I understand your question, but it may help to recall that the second arg to RewriteCond is a regexp so you could write something like:

RewriteCond %{HTTP_HOST} ^[a-z]+\.mysite\.com$ [NC]

As for excluding www you can chain rules (they are anded together) or get fancy with your regular expression. I'd suggest the former as it's generally easier to follow.

MarkusQ
A: 

I don't think you understood Gumbo's advice. I've included it here:

# stop rewriting for the host names example.com and www.example.com
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^ - [L]

RewriteRule ^error/(.*) index.php?error=$1 [L]
RewriteRule ^file/(.*) index.php?file=$1 [L]

This specifically performs no-rewrite for www.example.com and example.com. If we're on any other subdomain of example.com, the error/ and file/ rewrites apply.

If you wanted to invert the test, you could do something like this:

RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$
RewriteRule ^error/(.*) index.php?error=$1 [L]

RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$
RewriteRule ^file/(.*) index.php?file=$1 [L]
geocar
A: 

I used php and created a system for my framework, its more efficient and secure in many ways I think, but thanks alot for the advice!

:]<3

A: 

This got me out of similar situations building complex Regex, it might help you out as well.

http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/

Codex73