LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[Webdev] Mod_rewrite revisted yet again :-)

[Webdev] Mod_rewrite revisted yet again :-)

ad at m.beecher.net ad at m.beecher.net
Mon Nov 5 13:43:10 GMT 2001


> What if a section has a space or more in its name? So for example
> "Cooking Tips". With php I can urlencode this to /features/Cooking+Tips/
> But I would like to get mod_rewrite using the above rules to work
> this out.
>
Any particular reason why you need to do the regex within mod_rewrite? I
mean, unless there are files under /features that you want to skip - and you
can still get at those using passthru() or the other flesystem functions -
you gain much more control doing it from within PHP. Not only is it easier
to work with the regular expressions, but you can use even more complex
Perl-style regexes (PCRE) if you wish.

I really only use mod_rewrite for simple regex rules. In your example, I'd
be more inclined to map the whole of /features onto one PHP script, and let
the PHP script handle the URL rewriting. For example, I'm doing the
IrelandOffline Blackout website at the moment, with this set of RewriteRules
(this is on my development box, ignore the hostname and IP address):

<VirtualHost 192.168.0.2>
    ServerName blackout.irelandoffline.dev
    DocumentRoot /home/sites/irelandoffline.org/blackout
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/(scripts|images)
    RewriteRule .* /scripts/buildpage.php
</VirtualHost>

So basically, I'm passing through all the content pages on the site and
reading the $REQUEST_URI in the PHP script, rather than reading vars set in
the $QUERY_STRING. The same process could be used for your pages, just by
building a query out of the $REQUEST_URI. Of course, you *could* use
mod_rewrite regular expressions, but it all seems a bit OTT to me. I find it
much easier to handle it within the PHP script.

> PS. Thanks to Adam beacher for helping to get this far ;-)
>
No bother. And it's Beecher. :)

adam





More information about the Webdev mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell