Myspace Proxy - Mortgage - Balance Transfer Credit Cards - Facebook Proxy - Cell Phone

PDA

View Full Version : Easy solution to url rewriting problems


nullbit
Feb 23rd 2005, 7:28 am
I found this interesting (from apache's mod_rewrite engine manual):


External Rewriting Engine

Description:
A FAQ: How can we solve the FOO/BAR/QUUX/etc. problem? There seems no solution by the use of mod_rewrite...
Solution:
Use an external rewrite map, i.e. a program which acts like a rewrite map. It is run once on startup of Apache receives the requested URLs on STDIN and has to put the resulting (usually rewritten) URL on STDOUT (same order!).

RewriteEngine on
RewriteMap quux-map prg:/path/to/map.quux.pl
RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}

#!/path/to/perl

# disable buffered I/O which would lead
# to deadloops for the Apache server
$| = 1;

# read URLs one per line from stdin and
# generate substitution URL on stdout
while (<>) {
s|^foo/|bar/|;
print $_;
}

This is a demonstration-only example and just rewrites all URLs /~quux/foo/... to /~quux/bar/.... Actually you can program whatever you like. But notice that while such maps can be used also by an average user, only the system administrator can define it.


So basically, you can use external scripts in whatever language you prefer to help rewrite your URLs, which is good for more complex URL rewriting scenarios, when you haven't got the time to learn how to do everything natively using the module.

neterslandreau
Feb 23rd 2005, 12:40 pm
That is pretty neat. Thanks for pointing it out.

itsmani1
Mar 18th 2005, 3:27 am
here is the link of the site where i m trying to implement url rewrite

http://www.artologics.com/posters/index.php

now problem to me when i write this url

I wanted:

http://www.artologics.com/posters/catid/38

to be interpreted server side to mean this:

http://www.artologics.com/posters/index.php?catid=38


However, for the first link http://mannan.zabvision.edu.pk /catid/38, since the /catid/38 folders did not really exisit on the server. So I added the following code on my .htaccess file.

what i want system to do is : it should not replace the url (url that shuld remain same) but system should work as it is working :::

here is my .htaccess

RewriteEngine on
RewriteRule ^catid/([0-9]+)$ /posters/index.php?catid=$1 [R]
ReWriteRule ^pag/([a-z]+)$ /posters/index.php?pag=$1 [R]
ReWriteRule ^pag/css/([a-z]+.[a-z]+)$ /posters/css/$1 [R]
ReWriteRule ^pag/images/([a-z]+_[0-9]+.jpg)$ /posters/images/$1 [R]
ReWriteRule ^/catid/uploads/([a-z]+.jpg)$ /posters/uploads/$1 [R]
ReWriteRule ^catid/css/([a-z]+.[a-z]+)$ /posters/css/$1 [R]
ReWriteRule ^catid/images/([a-z]+_[0-9]+.jpg)$ /posters/images/$1 [R]
ReWriteRule ^/catid/uploads/([a-z]+.jpg)$ /posters/uploads/$1 [R]
RewriteRule ^subcat/([0-9]+)$ /posters/index.php?catid=$1 [R]
ReWriteRule ^subcat/css/([a-z]+.[a-z]+)$ /posters/css/$1 [R]
ReWriteRule ^subcat/images/([a-z]+_[0-9]+.jpg)$ /posters/images/$1 [R]
ReWriteRule ^/subcat/uploads/([a-z]+.jpg)$ /posters/uploads/$1 [R]

can any one help

itsmani1
Dec 18th 2005, 11:41 pm
Use this.its correct
Options +FollowSymLinks
RewriteEngine on
RewriteRule www/(.*)/(.*)/$ mannan.zabvision.edu.pk?$1=$2
-------------------------
mannan.zabvision.edu.pk?id=5/www/id/5/
for
mannan.zabvision.edu.pk?id=5

----------------------------

itsmani1
Dec 18th 2005, 11:42 pm
i can help in mod_rewire issue.
ppl can contact me.

itsmani1
Dec 18th 2005, 11:45 pm
thanx for every thing pplz.