Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2001, 05:13 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
My RewriteRule needs tweaking

---------Current mod_rewrite--------

RewriteEngine on
# Last RewriteRule for phpmyadmin to work
RewriteCond %{REQUEST_URI} ^/phpmyadmin.*
RewriteRule ^(.+) - [L]

# Last RewriteRule so I can grab my images
RewriteCond %{REQUEST_URI} ^/images.*
RewriteRule ^(.+) - [L]

# Last RewriteRule for my css
RewriteCond %{REQUEST_URI} ^/css.*
RewriteRule ^(.+) - [L]

#Last (and lastly) let every argument in the URI to be passed thru parser.php (which parses out the URI)
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^([A-Za-z0-9]+)/?$ parser.php?request=$1 [T=application/x-httpd-php,L]
RewriteRule ^(.+) parser.php?request=$1 [T=application/x-httpd-php,L]

---------My Problem--------
This has worked very well for me so far. However, now I want to restructure my site. I have many areas to my site (i.e. "Products", "Members", "Vendors", etc...). And what I would like is for them to have their own parser script.

Example...
http://domain/ProductsRest/of/URI/ (so anything after "Products" would be parsed by product_parser.php)
http://domain/Members/Rest/of/URI/ (...would be parsed by members_pasrer.php)
http://domain/Vendors/Rest/of/URI/ (...parsed by vendors_parser.php)

-------Would this be my tweak?-------
# Have anything after Members (i.e. http://domain/Members/Rest/of/URI) go thru members_parser.php
RewriteCond %{REQUEST_URI} ^/Members/(.*)$
RewriteRule ^([A-Za-z0-9]+)/?$ members_parser.php?request=$1 [T=application/x-httpd-php,L]
RewriteRule ^(.+) members_parser.php?request=$1 [T=application/x-httpd-php,L]

------Or this?------
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^Members/(.+) members_parser.php?request=$1 [T=application/x-httpd-php,L]

Along with those two I have tried just about every other mutation but no luck. Am I close? Any suggestions? Can you explain what I am doing wrong.

Thank you in advance,

Piet
__________________

- Please help us build our Hewlett Packard community
- Check us out, or tell someone who might find us useful

Last edited by piet : April 7th, 2003 at 03:41 PM.

Reply With Quote
  #2  
Old November 9th, 2001, 05:32 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
------Maybe this------
RewriteCond %{REQUEST_URI} ^/Members/([^/A-Za-z0-9]+)$
RewriteRule ^Members/(.+)$ /server/path/to/members_parser.php?request=$1 [T=application/x-httpd-php,L]

For your 3 ignore dirs, you should add [PT] like so:

RewriteCond %{REQUEST_URI} ^/phpmyadmin.*
RewriteRule ^(.+) - [PT,L]

Reply With Quote
  #3  
Old November 9th, 2001, 08:47 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
FreeBSD,

No luck. Do I have everything set up correctly?

Just so we are on the same page, my rewrite so far is this:

/* -------------------------- Rewrite ----------------------------*/
RewriteEngine on
# Last RewriteRule for phpmyadmin to work w/Passthru
RewriteCond %{REQUEST_URI} ^/phpmyadmin.*
RewriteRule ^(.+) - [PT,L]

# Last RewriteRule so I can grab my images w/Passthru
RewriteCond %{REQUEST_URI} ^/images.*
RewriteRule ^(.+) - [PT,L]

# Last RewriteRule for my css w/Passthru
RewriteCond %{REQUEST_URI} ^/css.*
RewriteRule ^(.+) - [PT,L]

# Last if 1st argument in URI is Members
RewriteCond %{REQUEST_URI} ^/Members/([^/A-Za-z0-9]+)$
RewriteRule ^Members/(.+)$ /path/to/member_parser.php?request=$1 [T=application/x-httpd-php,L]

#Last if 1st argument in URI is Products
RewriteCond %{REQUEST_URI} ^/Products/([^/A-Za-z0-9]+)$
RewriteRule ^Members/(.+)$ /path/to/products_parser.php?request=$1 [T=application/x-httpd-php,L]

# Last if 1st argument in URI is neither Members nor Products
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^(.+)$ /path/to/parser.php?request=$1 [T=application/x-httpd-php,L]

/* ---------------- End Rewrite ------------------------*/

Do you see anything wrong in this? I have tested this on Linux and NT and I get the sames results for both.

Piet

Last edited by piet : April 7th, 2003 at 03:42 PM.

Reply With Quote
  #4  
Old November 10th, 2001, 09:28 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Do you see anything wrong in this?

Yes. Remove the ^ should fix it like so:

RewriteCond %{REQUEST_URI} ^/Members/([/A-Za-z0-9]+)$

You also got a typo error on this line:

RewriteRule ^Members/(.+)$ /path/to/products_parser.php?request=$1 [T=application/x-httpd-php,L]

It should be ^Products/(.+)$

Have you enabled RewriteLog? If not, do so now for debugging. Whenever you requesting something that doesn't match, you should see pass through and not-matched.

Reply With Quote
  #5  
Old November 10th, 2001, 02:01 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Freebsd,

I have corrected my mistakes with your suggestions and it is not yet working. This is what's happening:

When I go to http://domain/ it brings me the index page. Great!
When I go to http://domain/Forums/ it goes to Forums. Great!
When I go to...
http://domain/Products/
or
http://domain/Members/

it doesn't seem to read my product_parser.php or member_parser.php scripts but instead it keeps on reading the catchall_parser.php (aka parser.php in the posts above) script.

Here is an excerpt from my RewriteLog (sorry for the lengthyness)

/* --------------RewriteLog-----------------*/

(4) RewriteCond: input='/Products/' pattern='^/(.*)$' => matched
(2) [per-dir /phpdev3/www/] rewrite products/ -> catchall_parser.php?request=products/
(3) split uri=catchall_parser.php?request=products/ -> uri=catchall_parser.php, args=request=products/
(3) [per-dir /phpdev3/www/] add per-dir prefix: catchall_parser.php -> /phpdev3/www/catchall_parser.php
(2) [per-dir /phpdev3/www/] remember /phpdev3/www/catchall_parser.php to have MIME-type 'application/x-httpd-php'
(2) [per-dir /phpdev3/www/] strip document_root prefix: /phpdev3/www/catchall_parser.php -> /catchall_parser.php
(1) [per-dir /phpdev3/www/] internal redirect with /catchall_parser.php [INTERNAL REDIRECT]
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/phpmyadmin.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/images.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/css.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^Members/(.+)$' to uri 'catchall_parser.php'
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^Products/(.+)$' to uri 'catchall_parser.php'
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)$' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/(.*)$' => matched
(2) [per-dir /phpdev3/www/] rewrite catchall_parser.php -> catchall_parser.php?request=catchall_parser.php
(3) split uri=catchall_parser.php?request=catchall_parser.php -> uri=catchall_parser.php, args=request=catchall_parser.php
(3) [per-dir /phpdev3/www/] add per-dir prefix: catchall_parser.php -> /phpdev3/www/catchall_parser.php
(2) [per-dir /phpdev3/www/] remember /phpdev3/www/catchall_parser.php to have MIME-type 'application/x-httpd-php'
(1) [per-dir /phpdev3/www/] initial URL equal rewritten URL: /phpdev3/www/catchall_parser.php [IGNORING REWRITE]
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/images/spacer.gif -> images/spacer.gif
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'images/spacer.gif'
(4) RewriteCond: input='/images/spacer.gif' pattern='^/phpmyadmin.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/images/spacer.gif -> images/spacer.gif
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'images/spacer.gif'
(4) RewriteCond: input='/images/spacer.gif' pattern='^/images.*' => matched
(2) forcing '/phpdev3/www/images/spacer.gif' to get passed through to next API URI-to-filename handler
(1) [per-dir /phpdev3/www/] initial URL equal rewritten URL: /phpdev3/www/images/spacer.gif [IGNORING REWRITE]
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'products/'
(4) RewriteCond: input='/Products/' pattern='^/phpmyadmin.*' => not-matched
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'products/'
(4) RewriteCond: input='/Products/' pattern='^/images.*' => not-matched
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'products/'
(4) RewriteCond: input='/Products/' pattern='^/css.*' => not-matched
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^Members/(.+)$' to uri 'products/'
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^Products/(.+)$' to uri 'products/'
(3) [per-dir /phpdev3/www/] add path-info postfix: /phpdev3/www/products -> /phpdev3/www/products/
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/products/ -> products/
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)$' to uri 'products/'
(4) RewriteCond: input='/Products/' pattern='^/(.*)$' => matched
(2) [per-dir /phpdev3/www/] rewrite products/ -> catchall_parser.php?request=products/
(3) split uri=catchall_parser.php?request=products/ -> uri=catchall_parser.php, args=request=products/
(3) [per-dir /phpdev3/www/] add per-dir prefix: catchall_parser.php -> /phpdev3/www/catchall_parser.php
(2) [per-dir /phpdev3/www/] remember /phpdev3/www/catchall_parser.php to have MIME-type 'application/x-httpd-php'
(2) [per-dir /phpdev3/www/] strip document_root prefix: /phpdev3/www/catchall_parser.php -> /catchall_parser.php
(1) [per-dir /phpdev3/www/] internal redirect with /catchall_parser.php [INTERNAL REDIRECT]
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/phpmyadmin.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/css.*' => not-matched
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^Members/(.+)$' to uri 'catchall_parser.php'
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^Products/(.+)$' to uri 'catchall_parser.php'
(3) [per-dir /phpdev3/www/] strip per-dir prefix: /phpdev3/www/catchall_parser.php -> catchall_parser.php
(3) [per-dir /phpdev3/www/] applying pattern '^(.+)$' to uri 'catchall_parser.php'
(4) RewriteCond: input='/catchall_parser.php' pattern='^/(.*)$' => matched
(2) [per-dir /phpdev3/www/] rewrite catchall_parser.php -> catchall_parser.php?request=catchall_parser.php
(3) split uri=catchall_parser.php?request=catchall_parser.php -> uri=catchall_parser.php, args=request=catchall_parser.php
(3) [per-dir /phpdev3/www/] add per-dir prefix: catchall_parser.php -> /phpdev3/www/catchall_parser.php
(2) [per-dir /phpdev3/www/] remember /phpdev3/www/catchall_parser.php to have MIME-type 'application/x-httpd-php'
(1) [per-dir /phpdev3/www/] initial URL equal rewritten URL: /phpdev3/www/catchall_parser.php [IGNORING REWRITE]

/* -----------End RewriteLog----------------*/


This is my first time reading a log but I am pretty sure it is telling me that the catchall_parser.php is always coming up, not products_parser or members_parser.php. It is strange b/c I have noticed in the first line there is a match :

RewriteCond: input='/Products/' pattern='^/(.*)$' => matched

Anymore help would be greatly appreciated.

Piet

Last edited by piet : April 7th, 2003 at 03:42 PM.

Reply With Quote
  #6  
Old November 10th, 2001, 02:38 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> it doesn't seem to read my product_parser.php

I found a problem with the design flaw.
When you go to http://domain/Products/abc/123

and if your http://domain/product_parser.php looks like so:

<?php
echo "$QUERY_STRING";
?>

You should get abc/123.

However, since your ^/Products/([/A-Za-z0-9]+)$ requires something after /Products/something_here, so requesting http://domain/Products/ would return not-matched.

How about changing ^/Products/([/A-Za-z0-9]+)$ to ^/Products([/A-Za-z0-9]*)$ like so:

RewriteCond %{REQUEST_URI} ^/Members([/A-Za-z0-9]*)$
RewriteRule ^Members(.*)$ /path/to/member_parser.php?request=$1 [T=application/x-httpd-php,L]

#Last if 1st argument in URI is Products
RewriteCond %{REQUEST_URI} ^/Products([/A-Za-z0-9]*)$
RewriteRule ^Products(.*)$ /path/to/products_parser.php?request=$1 [T=application/x-httpd-php,L]

With this changes, at least accessing to http://domain/Products or http://domain/Products/ matches your Product's condition and it's left for your product_parser.php to determine what to do with the QUERY_STRING.

Say going to http://domain/Products or http://domain/Products/, your $QUERY_STRING should be /, then have product_parser.php to display Please choose a product.

You saw this (4) RewriteCond: input='/Products/' pattern='^/(.*)$' => matched because it matches your catch-all parser.

Or you can even do this:
/* -------------------------- Rewrite ----------------------------*/
RewriteEngine on
# Last RewriteRule for phpmyadmin to work w/Passthru
RewriteCond %{REQUEST_URI} ^/phpmyadmin.*
RewriteRule ^(.+) - [PT,L]

# Last RewriteRule so I can grab my images w/Passthru
RewriteCond %{REQUEST_URI} ^/images.*
RewriteRule ^(.+) - [PT,L]

# Last RewriteRule for my css w/Passthru
RewriteCond %{REQUEST_URI} ^/css.*
RewriteRule ^(.+) - [PT,L]

# Last if 1st argument in URI is Members
RewriteCond %{REQUEST_URI} ^/Members/([/A-Za-z0-9]+)$
RewriteRule ^Members/(.+)$ /path/to/member_parser.php?request=$1 [T=application/x-httpd-php,L]

#Last if 1st argument in URI is Products
RewriteCond %{REQUEST_URI} ^/Products/([/A-Za-z0-9]+)$
RewriteRule ^Products/(.+)$ /path/to/products_parser.php?request=$1 [T=application/x-httpd-php,L]

RewriteCond %{REQUEST_URI} ^/Products/?$
RewriteRule ^(.*)$ /path/to/products_parser.php?no_product_selected [T=application/x-httpd-php,L]

RewriteCond %{REQUEST_URI} ^/Members/?$
RewriteRule ^(.*)$ /path/to/member_parser.php?no_member_selected [T=application/x-httpd-php,L]

# Last if 1st argument in URI is neither Members nor Products
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^(.+)$ /path/to/parser.php?request=$1 [T=application/x-httpd-php,L]

/* ---------------- End Rewrite ------------------------*/

Last edited by freebsd : November 10th, 2001 at 02:49 PM.

Reply With Quote
  #7  
Old November 11th, 2001, 02:14 PM
piet piet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bend, OR
Posts: 96 piet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Freebsd,

Finally! It works. Just so you know what worked and what didn't.

/*------------ Working -------------- */

# Last if 1st argument in URI is Members
RewriteCond %{REQUEST_URI} ^/Members/([/A-Za-z0-9]*)$
RewriteRule ^(.+)$ /path/to/member_parser.php?request=$1 [T=application/x-httpd-php,L]

/* ---------------------------------------*/



/* ----------Not Working -------------*/

# Last if 1st argument in URI is Members
RewriteCond %{REQUEST_URI} ^/Members/([/A-Za-z0-9]+)$
RewriteRule ^Members/(.+)$ /path/to/member_parser.php?request=$1 [T=application/x-httpd-php,L]

/*----------------------------------------*/


For some reason the RewriteRule beginning with ^Members/ didn't seem to work.

Thank you VERY much for your help.

Piet

Last edited by piet : April 7th, 2003 at 03:42 PM.

Reply With Quote
  #8  
Old November 11th, 2001, 03:43 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Just so you know what worked and what didn't.

Both should work. It's the fact that you shouldn't access it with http://domain/Members/nothing_here because your RewriteCond requires ([/A-Za-z0-9]+)$] and http://domain/Members/something_here

This RewriteRule ^Members/(.+)$ works fine if you pust something after Members/.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > My RewriteRule needs tweaking


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT