PDA

View Full Version : Modrewrite problems.


_Scott_
10-26-2005, 01:07 PM
I'm trying to use GET variables in a mod-rewritten URL. For example I'd originally have script?1=1&2=2 turns into script/1/2/ but then I want to add script/1/1/?3=3&4=4 but when I do this

print_r($_GET);

It can only get the variables 1 and 2 but not 3 and 4.

schleppel
10-26-2005, 03:27 PM
Showing us your rewrite rule would have been helpful... you should try using the [QSA] flag after your rule.

(QSA stands for Query String Append.)

_Scott_
10-27-2005, 03:44 AM
This is what the RewriteRule looks like:

RewriteRule ^view_tutorials/(.*)/(.*)/(.*)/ view_tutorials?page=$3&categorey=$1&scategorey=$2

I tried and made it

RewriteRule ^view_tutorials/(.*)/(.*)/(.*)/ view_tutorials?page=$3&categorey=$1&scategorey=$2 [QSA]

but it didn't do anything.

schleppel
10-27-2005, 11:01 AM
With this URL
http://localhost/view_tutorials/1/2/3/?4=5
and this rule (i actually had /view_tutorials.php?page=)
RewriteRule ^view_tutorials/([^/])/([^/])/([^/])/?$ view_tutorials?page=$3&categorey=$1&scategorey=$2 [QSA]
i got

Array
(
[page] => 3
[categorey] => 1
[scategorey] => 2
[4] => 5
)

_Scott_
10-27-2005, 12:59 PM
Well I used this URL

/view_tutorials/1/2/3/?4=5

And this rule (as you wrote)

RewriteRule ^view_tutorials/([^/])/([^/])/([^/])/?$ view_tutorials?page=$3&categorey=$1&scategorey=$2 [QSA]

I got

Array
(
[page] => 3
[categorey] => 1/2
[scategorey] => 3
)

Btw the reason why I don't get view_tutorials.php is because I added this

<Files view_tutorials>
SetHandler application/x-httpd-php
</Files>

and made the view_tutorials.php file just view_tutorials

schleppel
10-27-2005, 02:13 PM
I can't see why this doesn't work for you, maybe you have some conflicting rules?

One last thing you could try is this:
RewriteRule ^view_tutorials/([^/])/([^/])/([^/])/?$ view_tutorials?page=$3&categorey=$1&scategorey=$2&%{QUERY_STRING}

Edit: my test Urls removed.

_Scott_
10-27-2005, 11:16 PM
Well there is this before it:
RewriteRule ^view_tutorials/(.*)/(.*)/ view_tutorials?categorey=$1&scategorey=$2

It's there because there won't always be a page anda query string on every page, would this conflict with it?

schleppel
10-27-2005, 11:25 PM
This should have no conflicts and works for me.
RewriteEngine On

RewriteRule ^view_tutorials/([^/])/([^/])/?$ view_tutorials?categorey=$1&scategorey=$2 [QSA]
RewriteRule ^view_tutorials/([^/])/([^/])/([^/])/?$ view_tutorials?page=$3&categorey=$1&scategorey=$2 [QSA]

Edit: [QSA] only adds the query string if it exists.
(.*) means anything, including a /
([^/]) means anything that isn't a /

_Scott_
10-27-2005, 11:36 PM
Oh, that must be the problem then. My MySQL is down right now but I'll try it when it's up. I appreciate your help.

EDIT: I can't believe this, now it reads all of the query string variables but not the other variables like categorey and page!

schleppel
10-28-2005, 01:25 AM
I really don't see how this can be happening. Post your whole .htaccess file.

_Scott_
10-28-2005, 01:50 AM
EDIT: Nevermind I fixed it I had to make the regex part of it like this ([^/]+) instead of ([^/])

Thanks for your help though

schleppel
10-28-2005, 02:16 PM
I am very sorry i forgot that, that's why it worked for my single number tests. But i'm glad you got it working.