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

Optionally supporting mod_rewrite

Postby PCSpectra » Sat Nov 11, 2006 12:38 am

What methods do you use when your application uses mod_rewrite but you wish to provide a failsafe backup incase mod_rewrite is disabled???
Expecting something deep? Google Marianas Trench. :)
PCSpectra
DevNet Evangelist
 
Posts: 6031
Joined: Tue Dec 21, 2004 6:00 pm
Location: Winnipeg

Postby feyd » Sat Nov 11, 2006 12:44 am

  • path info
  • normal links
[feyd:蜘龍] - Jon | Forum Tour | Useful Posts
Most Helpful '05, '06; Best Code Snippet '05; IATM '06, '07; Best Avatar '07; | SHA256
You will be ignored if you contact me privately about code I did not write or support.
User avatar
feyd
Neighborhood Spidermoddy
 
Posts: 31559
Joined: Mon Mar 29, 2004 4:24 pm
Location: Germantown, Tennessee, USA

Postby PCSpectra » Sat Nov 11, 2006 1:02 am

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... :)
Expecting something deep? Google Marianas Trench. :)
PCSpectra
DevNet Evangelist
 
Posts: 6031
Joined: Tue Dec 21, 2004 6:00 pm
Location: Winnipeg

Postby feyd » Sat Nov 11, 2006 1:17 am

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.
[feyd:蜘龍] - Jon | Forum Tour | Useful Posts
Most Helpful '05, '06; Best Code Snippet '05; IATM '06, '07; Best Avatar '07; | SHA256
You will be ignored if you contact me privately about code I did not write or support.
User avatar
feyd
Neighborhood Spidermoddy
 
Posts: 31559
Joined: Mon Mar 29, 2004 4:24 pm
Location: Germantown, Tennessee, USA

Postby Chris Corbyn » Sat Nov 11, 2006 7:12 am

I'd look at how wordpress do it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
 
Posts: 13081
Joined: Wed Mar 24, 2004 8:57 am
Location: Melbourne, Australia

Postby johno » Sat Nov 11, 2006 1:33 pm

Try http://www.example.com/?somepath/anotherpath/ and look at $_SERVER['QUERY_STRING'];
User avatar
johno
Forum Commoner
 
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia

Postby m3mn0n » Sat Nov 11, 2006 3:25 pm

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.

Syntax: [ Download ] [ Hide ]
echo "blablabla.com/first/second/third/";


would be

Syntax: [ Download ] [ Hide ]
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
User avatar
m3mn0n
PHP Evangelist
 
Posts: 3545
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Postby PCSpectra » Sat Nov 11, 2006 5:10 pm

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
Expecting something deep? Google Marianas Trench. :)
PCSpectra
DevNet Evangelist
 
Posts: 6031
Joined: Tue Dec 21, 2004 6:00 pm
Location: Winnipeg

Postby johno » Sat Nov 11, 2006 5:21 pm

No problem man. Enjoy!
User avatar
johno
Forum Commoner
 
Posts: 36
Joined: Fri May 05, 2006 6:54 am
Location: Bratislava/Slovakia


Return to PHP - Theory and Design

Who is online

Users browsing this forum: No registered users and 1 guest