开发者

Config version check in Apache

I'm revamping an apache-php application. The main goal is to make it easily portable between hosts. I moved every path-dependent setting from .htaccess files to the virtualhost specification, but it would be nice being able to match the version of the config file to the version of the site.

What I thought of is two constants defined in the vhost config (as environment variables). Like:

  • lowVersion containing the lowest version of the application this config file is compatible with.
  • highVersion containing the version of the app when the last config file change happened.

So the application's central .htaccess file could check if:

  • if lowVersion is not bigger than the version of the application and
  • if high开发者_开发百科Version is not lower than the minimum config version needed by the app.

I know about SetEnv, SetEnvIf and Rewrite, but they don't seem to support comparing numbers in a greater-than and less-than fasshion.

Of course I could use a special number system like:

  • 3 = iii
  • 4 = iiii
  • etc

... and use RegEx to compare them (if one contains the other than it is greater), but there must be some more... prosfessional solution. :)


Apache's mod_rewrite can do a comparison like id > 1234 -- it will be done as string comparison though (lexicographically precedes and lexicographically follows).

Real-Life Example

Task: There are pages like /198655.html. Need to execute 301 redirect for all pages that have numbers between 152600 and 153655 to /us/ subfolder and all other into /en/ subfolder.

Code: http://pastebin.com/Jp7n8mdp

RewriteCond $1 >152600
RewriteCond $1 <153655
RewriteRule ^(\d+)\.html$ http://www.example.com/us/$1.html [R=301,L]
RewriteRule ^(\d+)\.html$ http://www.example.com/en/$1.html [R=301,L]

YOU CAN do number comparison -- it is not perfect and number has to be formatted accordingly .. but it is possible in simple cases. If you can make your numbers simple (e.g. comparing 04 < 11 and not 4 < 11) then it may work for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜