views:

572

answers:

6

I'm changing my site to show friendly URLs like this:

www.example.com/folder/topic

Works fine!

But when I add a parameter to the URL:

www.example.com/folder/topic?page=2

$_GET stops working. It doesn't recognise the parameter at all. Am I missing something?? The parameter worked fine before using full URLs.

+4  A: 

If you are using mod_rewrite then it is your rules that are broken. Either the query string is not being passed, or the mod_rewrite is discarding everything past /topic.

Try adding a rule that you can do: www.example.com/folder/topic/2

The Wicked Flea
Ah of course, thanks, that's it!!
A: 

Can you clarify what you mean by "friendly URLs" and "full URLs"? Are you reorganizing the directory structure, or using something like mod_rewrite?

JW
A: 

If you want to make your PHP URLs "friendly" you need to use something like Apache's mod_rewrite. Google something like "apache mod_write friendly url" and you will get plenty of articles on the subject.

Bill
+9  A: 

If it's a mod_rewrite problem, which it sounds like, you could add the [QSA] flag to your mod_rewrite rule, to append the query string to the rewritten URL instead of throwing it away.

Your rule will end up looking like:

RewriteRule from to [QSA]

MrZebra
A: 

I'm changing my site to show friendly URLs

Are you doing this using mod_rewrite or by reorganising your file structure? If the former, it's likely that your rules may need tweaking.

If it's a file re-organisation, what do you get when you print_r($_GET) in www.example.com/folder/topic?page=2?

ConroyP
A: 

MrZebra's answer is the correct one. It will allow you to continue to use query string as you do at the end of a URL, and you don't have to anticipate its presence one way or the other.

Brian Warshaw