Re: RewriteRules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Pruim wrote:

On Jan 12, 2009, at 2:16 PM, Nathan Rixham wrote:

Jason Pruim wrote:
Hi Everyone,
I know it's not a php question... But I know alot of you use rewrite rules and regular expressions and so I thought maybe you would be able to help me.
The site: HTTP://purl.raoset.com/test112
test112 doesn't exist.. It's driven by the database using this rewrite rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /p.php [L]
Now, on that site I have a few links... right now the likes are in the format of:
HTTP://purl.raoset.com/design.php?purl=test112
What I would like is to have it read:
HTTP://purl.raoset.com/test112/design
completing the total look of the site :)

technically the same code as above should work even if you change you're links.. you see it's just redirecting everything not found to p.php

so in p.php simply add in a
print_r($_SERVER);
exit();
at the top, upload to server then visit /test112/design in you're browser.. check the print_r output and you'll see the request in there, (variables sometimes differ, hence why I'm suggesting you check; you can skip this bit and jump right on to the next paragraph though)

you can then simply:
$request_page_parts = explode('/', $_SERVER['REQUEST_URI');
print_r($request_page_parts);

then use whatever code you want to display the correct page based on the uri requested (as you want)

I know this isn't the approach you expected but it basically hands off all page selection and processing to php, rather than a load of rewrite rules and lots of updating of .htaccess

if you really want the rewrite rules then I'm sure you've had many other accurate replies with examples :)

Nathan,

You get any drink you want as long as you come to me! Once I looked at it and read your e-mail it made total sense... I understand PHP programming better than rewrite rules :)




cool; couple of little notes to help you on you're way..

first thing you'll want to do is explode/split on "?" so that you have any get params stripped off and stored seperately for good measure next up it makes sense to check for and seperate file extensions, and likewise trim off trailing /'s

also experiment with this, you can do some nifty things; the last time I implemented it I had the following set up on my urls
domain.com/.wrapper/section/the_page_name.ext
in short, .wrapper was optional, and could be one of .ajax, .default, .print (output template differed dependant on the wrapper specified)
section and page name are both self explanatory
.ext was again optional, in one implementation I completely ignored it, meaning I could disguise the site as being all .html, or all .asp or .jsp or whatever (just for the novelty and to throw hackers) - in another implementation I used it wth extensions of .json .xml .php and .html (much like twitter) which turned the site into a kind of api.

I would recommend trying the above and making a system like this at some point, it's simpler than you think; but the benefits are immense, not becuase of the things you can do.. but because of the way it makes you program, it get's you to seperate the functional code from the presentation and really think about things - you learn lessons that never leave you :)

best wishes, nath

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux