I've did some research in how to rewrite my url with htaccess for an SEO friendly url, but I have a questions:
When i rewrite from index.php?news=1 to /news/1 would my $_GET['news']
still work? I can't seem to find an explanation on that. I want to be sure before I'll start implementing it into my website.
Thanks!
Yes, that will work as expected.
Specifically, mod_rewrite
's behavior with regards to existing query strings can be surprising. As an example, let's take the following rule, which converts the URL you supplied:
index.php?news=1 to /news/1
page name will be accessible through $_GET['news']
.
When i rewrite from index.php?news=1 to /news/1 would my $_GET['news'] still work?
Yes . $_GET['news']
is set because you have hardcoded news=1
into the rewritten query string.
If you have additional query parameters, it depends . If you've used the QSA
(query string append) flag then yes , otherwise $_GET['param']
would not be set in the URL:
/news/1?param=2
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.