config.ru for Pow + Wordpress - based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config.ru for Rackup + Wordpress, based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/ | |
# added hackery to work around wordpress issues - Patrick Anderson (patrick@trinity-ai.com) | |
# clearly this could be cleaner, but it does work | |
# And more hackery by @twombh to work in Linux environment | |
require 'rack' | |
require 'rack-legacy' | |
require 'rack-rewrite' | |
# patch Php from rack-legacy to substitute the original request so | |
# WP's redirect_canonical doesn't do an infinite redirect of / | |
module Rack | |
module Legacy | |
class Php | |
def run(env, path) | |
config = {'cgi.force_redirect' => 0} | |
config.merge! HtAccess.merge_all(path, public_dir) if @htaccess_enabled | |
config = config.collect {|(key, value)| "#{key}=#{value}"} | |
config.collect! {|kv| ['-d', kv]} | |
script, info = *path_parts(path) | |
env['SCRIPT_FILENAME'] = script | |
env['SCRIPT_NAME'] = strip_public script | |
env['PATH_INFO'] = info | |
env['REQUEST_URI'] = strip_public path | |
env['REQUEST_URI'] = env['ORIGINAL_REQUEST'] unless env['ORIGINAL_REQUEST'].nil? | |
super env, @php_exe, *config.flatten | |
end | |
end | |
end | |
end | |
INDEXES = ['index.html','index.php', 'index.cgi'] | |
use Rack::Rewrite do | |
rewrite %r{(.*$)}, lambda {|match, rack_env| | |
rack_env['ORIGINAL_REQUEST'] = rack_env['PATH_INFO'] | |
to_return = rack_env['PATH_INFO'] | |
if !File.exists?(File.join(Dir.getwd, rack_env['PATH_INFO'])) | |
to_return = '/index.php' | |
end | |
INDEXES.each do |index| | |
if File.exists?(File.join(Dir.getwd, rack_env['PATH_INFO'], index)) | |
to_return = File.join(rack_env['PATH_INFO'], index) | |
end | |
end | |
to_return | |
} | |
end | |
use Rack::Legacy::Php, Dir.getwd | |
use Rack::Legacy::Cgi, Dir.getwd | |
run Rack::File.new Dir.getwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment