Modifying and posting uri

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
How can I take a uri passed to a interface script(a script that is called  
for every page request) modify it, do whatever, and then change the uri that  
the user see's to be whatever?

Essentially I have a rewrite rule

RewriteRule ^(.*)[/]?$ /Index\.php

That calls index.php

I can do $_Server['REQUEST_URI'] to get the uri but how can I modify the  
browser's uri that the user see's but also redirect the uri to something  

Basically I sorta want to write a rewrite handler of my own because I'm  
having a few issues with it. I'd rather use php to deal with it if possible.


Re: Modifying and posting uri

Quoted text here. Click to load it

Essentially what I would like to do is modify  the uri with something like

$_Server['REQUEST_URI'] = '/MyPage/';

(as an example)

and it update the browsers uri but not effect anything else. (ofcourse if  
they uset that uri I will need to make sure it maps to something)

I know I can use rewrite rules and I'm trying to I am having more problems  
with them than it should be and I can handle it a lot easier in php(And  
atleast debug it so I know why things are failing).  

Re: Modifying and posting uri

Jon Slaughter wrote:
Quoted text here. Click to load it

You'll have to do this from the Apache end, not the client or your script.

The URI in the browser is what the browser uses to request the page.  
You can't just change it without affecting what the browser requests.  
So you'll have to have Apache change the request to something different.

You might be able to get some help in alt.apache.configuration.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Modifying and posting uri

Quoted text here. Click to load it

I think what John's asking is how to implement an MVC style approach,
and he's clearly got it working to a degree. A simple rewrite is
already in place on the server which directs all requests to the
Controller which then takes the value of this URI, and uses it to
"forward" the content (View).
However the changing of the URI in the address bar isnt really what
you need.
Your rewrites should not "redirect"  [ with 30x status] to the control
script, instead is uses the [L] flag to supress the address bar
change. The address bar however does change because all the links in
your application are generated by the application which understands
the layout model of your app.

So firstly it doesnt matter how the site is laid out, because your
controller can be setup [not the best way obviously] to go where your
content already is, BUT your Views, the html that you want to be
displayed should ideally not be heavily mixed with php that is written
for that page only and which contains absolute references to includes
[php classes etc...]. Instead you should hold the includes [database/
functions/classes etc...] all somewhere central, the references inside
the html [to things like images/css/js ...] should ideally all be
relative to the app root.
Then say you have a structure like this


using an array of page->view templates it is obviously possible for
your controller to realise that when a request for
(of the form /application/page/subpage/var1/var2/var3/ etc...)
comes in, it is to grab the URI, obtain the page, populate an array
with all the elements that the page should have (using the kind of
code that you probably have within /Music.php, and then find this
pages view [which is basically an empty html template with
placeholders for php variables] on the filesystem and include it,
which leads to the html output.

You are in a difficult situation because your code was written before
you thought about separation of code from content, so you have pages
which cannot just be included, or else various paths would be wrong,
but that would be one way to do this. Redirection using a header is
also one way but it will kill your page ranking - all those 302's) and
although changing the URLs as you wish doesnt address separation of
concerns (look and feel/programming ...)

My advice is to see this as a project, leave framesets behind,
concentrate on making the links generated by the MVC pattern human and
SE readable, and think about reducing the amount of repeated code
there is in each page, and try to abstract things like calls to mysql
and queries, in favour of building a query and passing it to a
function that makes the connection to the db and returns the query
results... after you have refactored your code, you will reap the
benefits of having implemented a true MVC pattern, and made your site
SO easy to maintain. (If you change to pgsql or decide to implement
security [login] you only have to update a single function, and a
small part of the model code. It might be work to refactor but it
really is worth it.

The Claw framework
which uses a Hierachical Model View Controller framework, is a great
example of what we are talking about, it too uses a single rewrite,
and then some decent code to abstract everything, it is a very nice
(but complex) piece of code I think. Look through the example
addressbook application, and the way the templates are held away from
the code that generates the rest of the html, how easy it would be to
add a few languages, etc... you will see!

Re: Modifying and posting uri

Wouldn't your own 404 handler do that for you?

Re: Modifying and posting uri

Quoted text here. Click to load it

Off Topic?
please always quote before you reply to something, but in this
context, a 404 handler is not relevant.

Site Timeline