|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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] |
|
#3
|
|||
|
|||
|
freebsd: thank you, thank you very much.
I'll put it to use and post back the results. |
|
#4
|
||||
|
||||
|
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:
I tried it with the following parts at the top: PHP Code:
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 |
|
#5
|
|||
|
|||
|
>> 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 |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > explicit mod_rewrite rule request |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|