Forum Moderators: phranque

Message Too Old, No Replies

PHP version tracker & Chained rewrite

         

zyron

3:33 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Hi!

I've been trying to find out what this PHP version tracker is, but searching on google haven't given me any answers - except other people wondering the same.

Any information would be of help.
My guess is that there are some people that are checking domains for what version of php is running, in order to do exploits.

My other question is how I can rewrite this so that I don't have to write the same RewriteCond for every RewriteRule....?

---
RewriteCond %{HTTP_HOST}!www\.domain\.com$
RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^$ domain2/index.html [L] #index file

RewriteCond %{HTTP_HOST}!www\.domain\.com$
RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule (.+)/ $domain2/$1/index.html [L] #subfolders

RewriteCond %{HTTP_HOST}!www\.domain\.com$
RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule (.+)$ domain2/$1 [L] #subfiles

I'm using a webhotell with a dedicated IP to handle many domains. This code just redirect to another folder, but I want to do this with as few lines as possible.

Cheers
Lars

jdMorgan

7:56 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is confusing. Why are you checking for NOT(www.domain.com) and then checking for ==domain2.com? If the second RewriteCond is true, the first will also be true, since domain2.com is not equal to www.domain.com.

Before getting into methods to compact this, code, we need to understand its purpose clearly.


RewriteCond %{HTTP_HOST}!www\.domain\.com$
RewriteCond %{HTTP_HOST} domain2\.com$

Jim

sitz

10:17 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Alternatively, why not disable displaying the PHP version? Use the ServerTokens [httpd.apache.org] directive to stop apache from displaying the PHP string in the 'Server' response header, and the X-Powered-By header can be disable by using the expose_php [us3.php.net] config option in your php.ini file.

zyron

3:29 pm on Jul 9, 2005 (gmt 0)

10+ Year Member



Hi!

Actually is that first line not necessary. I put it there for debugging, making sure that no rewrite is being done on that www.domain.com domain..

So, it should look like this:

RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^$ domain2/index.html [L] #index file

RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule (.+)/$ domain2/$1/index.html [L] #subfolders

RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule (.+)$ domain2/$1 [L] #subfiles

And I want to reduce it to something like this, but so that all RewriteCond is valid for all the rules:

RewriteCond %{HTTP_HOST} domain2\.com$
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^$ domain2/index.html [L] #index file
RewriteRule (.+)/$ domain2/$1/index.html [L] #subfolders
RewriteRule (.+)$ domain2/$1 [L] #subfiles

Is that possible by adding [C] or something similar?

jdMorgan

8:14 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought I answered this question recently, but I can't find it.

The easiest way to 'share' RewriteConds is to take the opposite sense of the conditions, and skip the rules, instead of executing them.

Also, if you test for HTTP_HOST=SomeDomain, then there is no need to test for HTTP_HOST NOT=SomeOtherDomain.

Do not end-anchor domains. Otherwise, a browser or user appending a port number (domain.com:80) will break the rule.

Comments must be on a separate line. Otherwise, they may cause error warnings, fill up your error log, and slow down your server.

Given all that, you could use something like this:


# If request is not to domain2 or file exists, skip next three rules
RewriteCond %{HTTP_HOST} !domain2\.com [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [S=3]
#
# Index
RewriteRule ^$ /domain2/index.html [L]
# Subfolders
RewriteRule ^(.+)/$ /domain2/$1/index.html [L]
# Subfiles
RewriteRule ^(.+)$ /domain2/$1 [L]

Jim