httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edwards Jim <...@ur.se>
Subject RE: [users@httpd] mod_rewrite question
Date Thu, 11 Dec 2003 15:04:25 GMT
Thanks, I'm busy trying it out...

/jim

-----Original Message-----
From: Robert Andersson [mailto:robert@profundis.nu] 
Sent: den 11 december 2003 06:49
To: users@httpd.apache.org
Subject: Re: [users@httpd] mod_rewrite question

Edwards Jim wrote:
> I need to rewrite some URLs:
> Case 1:
> http://localhost/folder/parent.php
>     -> http://localhost/parent
>
> Case 2:
> http://localhost/folder/child.php?parent=parent
>     -> http://localhost/parent/child
>
> is this possible using mod_rewrite on Apache.

Probably. I am not certain of the semantics here, but assuming both "parent"
and "child" are variable names, this would do it:

    RewriteEngine On
    RewriteRule ^/folder/(\w+)\.php /$1/
    RewriteRule ^/folder/(\w+)\.php\?parent=(\w+) /$2/$1

I added a trailing slash to the first case, as I assumed it's was a
directory? You might need to change "(\w+)" to be a character class to
include whatever characters "parent" or "child" might contains, eg:
"([\w-_\.]+)", or maybe just "(.+)". If you're not very familiar with
regular expressions you should read:

    http://www.perldoc.com/perl5.6.1/pod/perlre.html

Regards,
Robert Andersson


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message