mod_rewrite: multiple RewriteRules do not work well together
Posted: Tue Aug 08, 2006 3:54 pm
I have a "multiple RewriteRules" problem on a website using wildcard DNS.
Generally, any request for http://something.domain.com/file.html should be served from http://domain.com/MAIN_DIR/something/file.html . I am using the below code for this purpose (which has been written by someone else) and it has been working just fine.
However, I have problems with search engine spiders which look for the robots.txt file in http://domain.com/MAIN_DIR/something/ and don't find it there. My apache log is full of page not found errors because of it and I am somewhat worried it may increase server load.
So I want to redirect all requests for http://something.domain.com/robots.txt (or actually http://domain.com/MAIN_DIR/something/robots.txt) to http://domain.com/robots.txt. I've tried this code in .htaccess so solve it:
This code does indeed work but it does not when used together with the other RewriteRules code I mentioned above. I have placed it before that code so my .htaccess looks like:
I thought the [S=2] flag would have helped but it has not. I have to admit I am not good at this stuff so I suppose I may have missed something.
Any help is very welcome!
Tomas
Generally, any request for http://something.domain.com/file.html should be served from http://domain.com/MAIN_DIR/something/file.html . I am using the below code for this purpose (which has been written by someone else) and it has been working just fine.
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.MYDOMAIN\.COM$
RewriteCond %{HTTP_HOST} !^(www\.)?MYDOMAIN\.COM$
RewriteCond %{REQUEST_URI} !^/MAIN_DIR/
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.MYDOMAIN\.COM(.*) /MAIN_DIR/$1/$2So I want to redirect all requests for http://something.domain.com/robots.txt (or actually http://domain.com/MAIN_DIR/something/robots.txt) to http://domain.com/robots.txt. I've tried this code in .htaccess so solve it:
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.%{HTTP_HOST}/robots.txt$
RewriteRule ^/$ %{HTTP_HOST}/robots.txt [L,S=2]Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.%{HTTP_HOST}/robots.txt$
RewriteRule ^/$ %{HTTP_HOST}/robots.txt [L,S=2]
RewriteCond %{HTTP_HOST} ^[^.]+\.MYDOMAIN\.COM$
RewriteCond %{HTTP_HOST} !^(www\.)?MYDOMAIN\.COM$
RewriteCond %{REQUEST_URI} !^/MAIN_DIR/
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.MYDOMAIN\.COM(.*) /MAIN_DIR/$1/$2Any help is very welcome!
Tomas