0

I want to test for test.com and serve a particular file if I find it anywhere in the request, and if I don't find it move on to the rest of the rules. I can't get it to consistently do this.

RewriteRule ^/test.com /var/www/html/index.html [NC,L]

1
  • Can you clarify what you mean? Are you looking to act on requests sent to test.com, or ones with test.com as part of the file or directory structure in the request? – Shane Madden Sep 14 '11 at 22:09
0

The ^ means start of line/string, so requests to http://example.com/test.com and https://www.example.com/test.com_with_more should match, but http://example.com/in_front_test.com would not match. Try removing the ^ and prefix the . with a \ so that it matches a . and not any char use

RewriteRule test\.com /var/www/html/index.html [NC,L]

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule was used as a reference.

2
  • Thanks for your response, it's very helpful. I'm still having an issue with www.test.com vs test.com. I would think the folliowing would match either, but it doesn't seem to be the case: RewriteRule test\.com /var/www/html/index.html [NC,L] – d_b_g Sep 15 '11 at 14:12
  • I would think it would work too. Does example.com/in_front_test.com work, but not example.com/www.test.com? – becomingwisest Sep 15 '11 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.