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 May 9th, 2001, 07:58 AM
austegard austegard is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 2 austegard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question explicit mod_rewrite rule request

This is a shameless request for specific coding help - i.e. I need someone to do my work for me...

I am looking at putting in a mod_rewrite rule that would cause a URL like
Code:
http://oskar.austegard.com/articles/thecategory/thearticle/optionalparam/

to be interpreted by PHP as a call to
Code:
http://austegard.com/articles.php?u=oskar&p1=thecategory&p2=thearticle&p3=optionalparam


In other words, I am trying to make both the third level domain name and the apparent filesystem dynamic (there is no virtual host called oskar, I have a canonical wildcard in place, and there is no directory structure like article/thecategory/thearticle/...).

I know, I know - there's a lengthy thread on this at URL with some excellent examples, but none is very clear (the lack of comments makes it hard to figure out which rule does exactly what) and I am still not at all sure what is done in order to combine multiple rules.

Can anyone help? It seems this is a setup that would be useful for a LOT of people out there.

Any help would be much appreciated.

Thanks,

Oskar.

Reply With Quote
  #2  
Old May 9th, 2001, 07:07 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
RewriteEngine on

# the following two lines are for debugging purpose, uncomment them when everything works
RewriteLog "/path/to/rewrite.log"
RewriteLogLevel 9

# this line is two convert OSKAR.austegard.CoM to oskar.austegard.com
RewriteMap lc int:tolower

# continue the rest of the rules only if HTTP_HOST is oskar.austegard.com
RewriteCond %{HTTP_HOST} ^oskar\.austegard\.com$ [NC]

# /icons directory is reserved for global use, don't remove it
RewriteRule ^/icons/(.+) - [PT,L]

# reassign HTTP_HOST env var and carry over to the next rule
RewriteRule ^(.+) %{HTTP_HOST}=$1 [C]

# converting uppercase HTTP_HOST to lowercase
RewriteRule ^(.*)=(.*) ${lc:$1}$2 [C]

# ([^.]+) can not be blank, in fact, it must be oskar, not OSKAR by now. If it's something else,
# then request_uri become /articles.php?u=something_else, which obviously screw up your
# script. So you may need to adjust this for reliability or security
# thecategory -> $2
# thearticle -> $3
# optionalparam -> $4
# T=application/x-httpd-php to tell Apache articles.php is a PHP script
# L is to stop it
# the slash \ prior to any & character may not be needed.
# According to forefront (from that long thread you posted) test result, it was required for his rules to work properly
# put the following two lines (due to line break) on the same line
RewriteRule ^([^.]+)\.austegard\.com/articles/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ /server/path/to/docroot/articles.php?u=$1\&p1=$2\&p2=$3\&p3=$4 [T=application/x-httpd-php,L]

Reply With Quote
  #3  
Old May 10th, 2001, 06:36 AM
austegard austegard is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 2 austegard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Thanks!

freebsd: thank you, thank you very much.

I'll put it to use and post back the results.

Reply With Quote
  #4  
Old November 1st, 2001, 09:58 AM
m0nk3y's Avatar
m0nk3y m0nk3y is offline
Certified m0nk3y!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Posts: 437 m0nk3y User rank is Lance Corporal (50 - 100 Reputation Level)m0nk3y User rank is Lance Corporal (50 - 100 Reputation Level)m0nk3y User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 23 m 38 sec
Reputation Power: 8
Send a message via MSN to m0nk3y
i was going through this post and it had just what i wanted except i wanted

http://localhost/

instead of

http://oskar.austegard.com

How would the code change??

would it be something like this:

PHP Code:
<Directory "/apache/htdocs"
RewriteEngine on 
RewriteCond 
%{HTTP_HOST} ^localhost$ [NC
RewriteRule ^/icons/(.+) - [PT,L
RewriteRule ^(.+) %{HTTP_HOST}=$[C
RewriteRule ^(.*)=(.*) ${lc:$1}$[C
RewriteRule ^([^.]+)localhost/articles/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/([A-Za-z0-9_]*)/?$ /apache/htdocs/articles.php?u=$1&p1=$2&p2=$3&p3=$[T=application/x-httpd-php,L]
</
Directory


I tried it with the following parts at the top:

PHP Code:
# the following two lines are for debugging purpose, uncomment them when everything works 
RewriteLog "/path/to/rewrite.log" 
RewriteLogLevel 9 

# this line is two convert OSKAR.austegard.CoM to oskar.austegard.com 
RewriteMap lc int:tolower 


but apache said that it was not allowed there and when i removed it, it said RewriteMap was not allowed there either.

So i didnt use any of those, but now when i try and use it, it wont work at all, it just says:

404 Not Found

The requested URL /articles/php/hello/page/ was not found on this server

Can u please help?

my directory is C:/apache/htdocs/articles.php

im using all up-to-date software, such as PHP and Apache and im using Win 2k pro.
__________________
---------
Linux...Macs.... there boring, they just work....... Windows users on the other hand have all the fun!!
---------
PHP | MySQL | Apache | Zend

Reply With Quote
  #5  
Old November 1st, 2001, 06:12 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
>> would it be something like this:

No. For localhost you don't need to use RewriteMap to convert the HTTP_HOST part.

>> it was not allowed there and when i removed it

This line -> RewriteRule ^(.*)=(.*) ${lc:$1}$2 [C] needs RewriteMap's lc variable.

>> such as PHP and Apache and im using Win 2k pro

When it comes to Apache on win32, I know nothing. It also doesn't work well and non-standard and lack of some features. So same code that works on UNIX might not work on win32.

I suggest you to check for other examples:

1) http://forums.devshed.com/showthrea...4687&forumid=15
2) http://forums.devshed.com/showthrea...1293&forumid=15

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > explicit mod_rewrite rule request


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 1 hosted by Hostway
Stay green...Green IT