complicated mod_rewrite

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

complicated mod_rewrite

Post by alex.barylski »

Is there a way based on the extension of a URL (PHP or HTML) you can redirect the URL and it's parts accordingly???
some_title.html = index.php?page=some_title
some_script.php = index.php?script=some_script
Can you please show me the exact regex required for this?

Code: Select all

#RewriteEngine on
#RewriteRule ^([^/\.]+)/?$ index.php?url=$1 [L]
The above works on recognizing preceeding folders but I need to match the extensions I assume for the to work and use some kind of conditional magic???

Cheers :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: complicated mod_rewrite

Post by timvw »

(untested)

RewriteRule ^(.*?)\.html$ /index.php?page=$1 [L]
RewriteRule ^(.*?)\.php$ /index.php?script=$1 [L]

probably needs some improvement to allow anchors in the url...
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: complicated mod_rewrite

Post by alex.barylski »

timvw wrote:(untested)

RewriteRule ^(.*?)\.html$ /index.php?page=$1 [L]
RewriteRule ^(.*?)\.php$ /index.php?script=$1 [L]

probably needs some improvement to allow anchors in the url...
Cool thanks timvw...one question, by anchors you mean?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i wanted to say that i was not sure that an url like test.php?id=a#foo would be matched...
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

need rule that can send
/xxxxxx/111111/abc.html to index.php?cid=111111

any help in the rule?

thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

itsmani1 wrote:need rule that can send
/xxxxxx/111111/abc.html to index.php?cid=111111
Shouldn't you have learned not to hijack threads by now?
What have you tried so far?
And what was your reasoning behind the attempts?
Post Reply