PDA

View Full Version : mod_rewrite questions


Jacobb123
12-15-2007, 07:57 PM
I have done some mod rewrites but have some questions because my scripts are not executing like they should because of $_GET issues.

my rewrite rule is this
^question/(.*)/(.*)/(.*)?$ /viewtopic.php?cat_id=$1&f=$2&id=$3

I have the URL as /question/arts-and-humanities/visual-arts/test-question

Now my question is this with a mod_rewrite is the script that I am executing reading the actual url? is it reading viewtopic.php?cat_id=1&f=2&id=3 or is it reading the /question/arts-and-humanities/visual-arts/test-question


I ask because I am having some problems setting up my queries

I am doing this

$cat_title = $_GET['cat_id'];
$ncat_id = get_cat_id(str_replace("-"," ",str_replace("and","&",$cat_title)),$hostname,$dbuser,$dbpass,$db);

$forum_title = $_GET['f'];
$f_id = get_cat_id(str_replace("-"," ",str_replace("and","&",$forum_title)),$hostname,$dbuser,$dbpass,$db);
$post_id = $_GET['id'];
$post_id1 = get_cat_id(str_replace("-"," ",str_replace("and","&",$post_id)),$hostname,$dbuser,$dbpass,$db);



When I echo the $_GET['f'] it returns the value "visual-arts" but when I echo the value for $f_id it returns "1"

So I am not sure what is going on or exactly how this works. I am hoping someone could explain it to me.

oesxyl
12-15-2007, 08:19 PM
I have done some mod rewrites but have some questions because my scripts are not executing like they should because of $_GET issues.

my rewrite rule is this
^question/(.*)/(.*)/(.*)?$ /viewtopic.php?cat_id=$1&f=$2&id=$3

I have the URL as /question/arts-and-humanities/visual-arts/test-question


$1 = arts-and-humanities
$2 = visual-arts
$3 = test-question

. means "any char" with few exception
* means 0 or more
+ means 1 or more, this I think must replace * in your rewrite rule
() group what is inside into $n n=1-3 in this case

Now my question is this with a mod_rewrite is the script that I am executing reading the actual url? is it reading viewtopic.php?cat_id=1&f=2&id=3 or is it reading the /question/arts-and-humanities/visual-arts/test-question

I ask because I am having some problems setting up my queries

I am doing this

$cat_title = $_GET['cat_id'];
$ncat_id = get_cat_id(str_replace("-"," ",str_replace("and","&",$cat_title)),$hostname,$dbuser,$dbpass,$db);

$forum_title = $_GET['f'];
$f_id = get_cat_id(str_replace("-"," ",str_replace("and","&",$forum_title)),$hostname,$dbuser,$dbpass,$db);
$post_id = $_GET['id'];
$post_id1 = get_cat_id(str_replace("-"," ",str_replace("and","&",$post_id)),$hostname,$dbuser,$dbpass,$db);



When I echo the $_GET['f'] it returns the value "visual-arts" but when I echo the value for $f_id it returns "1"

So I am not sure what is going on or exactly how this works. I am hoping someone could explain it to me.

The problem I think is in php code, try to echo step by step to see where go wrong.

best regards

Inigoesdr
12-15-2007, 10:36 PM
Now my question is this with a mod_rewrite is the script that I am executing reading the actual url? is it reading viewtopic.php?cat_id=1&f=2&id=3 or is it reading the /question/arts-and-humanities/visual-arts/test-question

It's reading the latter. var_dump($_GET) to see the value of your url variables.
When I echo the $_GET['f'] it returns the value "visual-arts" but when I echo the value for $f_id it returns "1"
get_cat_id() is modifying it.

Jacobb123
12-15-2007, 10:41 PM
Thanks that answered my question and I can now understand the function. Thanks