URL Rewriting for Beginners
addedbytes.com
addedbytes.com
<Location /dostuff>
SetHandler mod_python
PythonHandler DoStuff
</Location>
Any request starting with /dostuff gets passed to DoStuff handler and you can parse the url pieces in the handler itself: from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
print >> req, 'uri = %s' % req.uri
print >> req, 'filename = %s' % req.filename
print >> req, 'path_info = %s' % req.path_info
return apache.OK require 'rubygems'
require 'sinatra'
get '/:name' do
"Your name is #{param[:name]}"
endIt's almost always a better idea to do this another way. Note that the distinction between the "handler" part of the URL, the remaining "path-like" part and the query string is already exposed in the CGI variables (SCRIPT_NAME, PATH_INFO, and QUERY_STRING). The handlers can do this magic on their own. Doing it by placing important application code into the apache configuration for the site strikes me as very confusing.
Kohana (PHP Framework) has pretty good URL rewriting resembling RoR's. /controller/method/variable. (/user/edit/1005 would reference application/controllers/user.php, class User_Controller, function user(1005).) POST/GET/PUT/etc are retained.
How does mod rewrite affect GET operations in PHP? If you rewrite the URL: http://www.example.com?id=1 to http://www.example.com/1/
And your code uses GET to grab the id from the URL. Does this still work? Or is the mod rewrite processed afterwards?