Page 1 of 1

Mod Rewrite Help

Posted: Wed May 23, 2007 4:58 am
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.

Posted: Wed May 23, 2007 6:49 am
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.

Posted: Wed May 30, 2007 9:12 am
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

Posted: Wed May 30, 2007 9:13 am
by feyd
I think you're looking for the [QSA] flag.

Posted: Wed May 30, 2007 9:22 am
by shiznatix
feyd wrote:I think you're looking for the [QSA] flag.
scratch my back with a hacksaw. you win

Posted: Wed May 30, 2007 9:40 am
by superdezign
shiznatix wrote:scratch my back with a hacksaw.
Ew.