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.
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]
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
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.
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
?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.