Mod Rewrite Help

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

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Mod Rewrite Help

Post by shiznatix »

I am posting this here because there is regex and whatnot with mod_rewrite. If this is in the wrong forum please move it.

And on to my question...

I want to make a rewrite rule that would turn this:
http://server/news/
into:
http://server/news.php

but I also want to turn any extra directorys into GET params like this:
http://server/news/new/
into:
http://server/news.php?_view=new

As I am terrible at regex and nearly clueless on mod_rewrite I was wondering if I could get a little help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm pretty sure we have examples of this behavior in multiple threads on rewrite. They would either be in here (Regex) or in Installation and Configuration.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Ok I got everything going nicely but I am still having a few problems. I want to keep all get parameters intact and showing. For example:

I have this url: http://localhost/languages/update/?fk_entry=2

and I have this rewrite rules list:

Code: Select all

RewriteRule ^([a-z]*)/([a-z]*)$ $1.php?_view=$2
RewriteRule ^([a-z]*)/([a-z]*)/$ $1.php?_view=$2
this will remove the fk_entry=2 param, but I need to keep that because what I want the URL to look like is this:
http://localhost/languages.php?_view=update&fk_entry=2

I have tried this rule but to no avail:

Code: Select all

RewriteRule ^([a-z]*)/([a-z]*)(\?*)$ $1.php?_view=$2&$3
RewriteRule ^([a-z]*)/([a-z]*)/(\?*)$ $1.php?_view=$2&$3
any help would be fantastic
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think you're looking for the [QSA] flag.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

feyd wrote:I think you're looking for the [QSA] flag.
scratch my back with a hacksaw. you win
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

shiznatix wrote:scratch my back with a hacksaw.
Ew.
Post Reply