Optionally supporting mod_rewrite

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Optionally supporting mod_rewrite

Post by alex.barylski »

What methods do you use when your application uses mod_rewrite but you wish to provide a failsafe backup incase mod_rewrite is disabled???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  • path info
  • normal links
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:
  • path info
  • normal links
You really don't feel like spending much time replying to me tonight do you? :lol: I'm looking for technique here...I have a few ideas...but I'm curious what others might come up with...

For instance a less than ideal method might consist of template logic which checks for mod_rewrite and outputs a link accordingly...a better approach might be using the same technique that session funcitons do when cookies aren't available...

What technique do you use...maybe something better than the above...which I'd love to hear... :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The concept is to have a class for each link type and detection code that can tell you which is best to use for any given page request. So long as you have a unified way of referencing files, it shouldn't be too much of a problem for it to handle all link generations.

I personally don't care about mod_rewrite or so called "search-engine-friendly" URLs.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'd look at how wordpress do it.
User avatar
johno
Forum Commoner
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia
Contact:

Post by johno »

Try http://www.example.com/?somepath/anotherpath/ and look at $_SERVER['QUERY_STRING'];
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

First, make sure you use the mod_rewrite flags QSA and L

then because the query arguments are being secretly passed still as variables you can use like normal ( eg. $_REQUEST['first'], etc. ) simply develop a function in place of the actual URLS.

eg.

Code: Select all

echo "blablabla.com/first/second/third/";
would be

Code: Select all

echo "blablabla.com/". ReWrite("first", "second", "third) ."/";
Then in this function you can make a check for a mod_rewrite variable being set to ON or OFF.

Then based on that you can deliver the urls...

if mod_rewrite was on, the above code would output:
blablabla.com/first/second/third/
if mod_rewrite was off, the above code would output:
blablabla.com/index.php?variable1=first&variable2=second&variable3=third
and because it's a function, you can change variable names to be output based on what first variable was sent in for example, like a reverse mod_rewrite


That's how I'd do it, but then again, I'd just say get mod_rewrite or don't use this app :P
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

johno wrote:Try http://www.example.com/?somepath/anotherpath/ and look at $_SERVER['QUERY_STRING'];
Boom, thats brilliant!!! :P Didn't even think of that...wicked thanks dude
User avatar
johno
Forum Commoner
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia
Contact:

Post by johno »

No problem man. Enjoy!
Post Reply