Welcome to WebmasterWorld Guest from 18.210.28.227

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

write mod to override request uri

     
3:50 pm on Apr 15, 2015 (gmt 0)

New User

joined:Apr 15, 2015
posts: 1
votes: 0


Hi everyone!

I'm trying to write a module for apache, this module must rewrite the Request URI incoming.

My goal is change the Request URI in transparent mode, such that the mod_php works with the variable $_SERVER['REQUEST_URI'] different from original.

I dev a custom mod, in hook "ap_hook_translate_name" I try to override a propery request r->uri, but if I print the variable "$_SERVER['REQUEST_URI']" in ar sample script I find the original Request URI.

The only variable correctly change is in $_SERVER['PHP_SELF'].

Someone ever had this problem?

Excuse me for the brutality of the post :)
4:33 pm on Apr 15, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4567
votes: 367


Hi tregua87 and welcome to the forums. It helps you get the best response if people reading your question get a little more information about the environment of the question. Are you editing within a CMS? If so, is it your own script, WordPress or something else? From the question it looks like something you could address in htaccess rather than PHP, but I am guessing without a little more detail.

You can use relevant code examples here just keeping things private by replacing actual domains with example.com - this would help others see what has been tried and look for solutions to that.
7:54 pm on Apr 15, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15943
votes: 890


When you say "apache mod" are you talking about a full-fledged third-party mod that would run as part of your Apache installation? Your own, or potentially other people's too? How do you force it to execute before mod_php?

It's often useful to step back and explain in English (sorry, I do realize it is not your native language) what you're trying to do. People tend to get fixated on some particular means or method, and overlook other ways to achieve the same end or goal. Why can't it be done with a RewriteMap, or an environmental variable, to pick just two possibilities?
12:10 am on Apr 22, 2015 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11875
votes: 246


welcome to WebmasterWorld, tregua87!

from PHP: $_SERVER - Manual:
http://php.net/manual/en/reserved.variables.server.php [php.net]
PHP: $_SERVER - Manual (in french):
http://php.net/manual/fr/reserved.variables.server.php [php.net]
'PATH_TRANSLATED'
Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

'SCRIPT_NAME'
Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

'REQUEST_URI'
The URI which was given in order to access this page; for instance, '/index.html'.


note how the three indices for $_SERVER differ.


https://httpd.apache.org/docs/2.4/developer/modguide.html [httpd.apache.org]:
ap_hook_translate_name: Place a hook that executes when a URI needs to be translated into a filename on the server (think mod_rewrite)



if i understand correctly, your apache module is part of the virtual-to-real mapping process, as would be mod_rewrite, so you would be affecting $_SERVER['PATH_TRANSLATED'] and $_SERVER['SCRIPT_NAME'] but not $_SERVER['REQUEST_URI'].