HELP WITH A PARTICULAR REWRITE RULE

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
bulletck
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 1:47 pm

HELP WITH A PARTICULAR REWRITE RULE

Post by bulletck »

I need a regular expression to do the following:

if someone goes to http://example.com/a the actual served page is http://example.com/a.php

and also http://example.com/a/b/c/d to render http://example.com/a_b_c_d.php, etc.
bulletck
Forum Newbie
Posts: 2
Joined: Wed Oct 29, 2008 1:47 pm

Re: HELP WITH A PARTICULAR REWRITE RULE

Post by bulletck »

Any thoughts?
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: HELP WITH A PARTICULAR REWRITE RULE

Post by prometheuzz »

bulletck wrote:I need a regular expression to do the following:

if someone goes to http://example.com/a the actual served page is http://example.com/a.php

and also http://example.com/a/b/c/d to render http://example.com/a_b_c_d.php, etc.
IMO, it's not possible with one rewrite rule. So you will have to use several:

Code: Select all

RewriteRule   ^([^/]+)/?$                   $1.php
RewriteRule   ^([^/]+)/([^/]+)/?$           $1_$2.php
RewriteRule   ^([^/]+)/([^/]+)/([^/]+)/?$   $1_$2_$3.php
etc.
Post Reply