URL rewriting tip needed
I made some searches on the web about URL rewriting, and found some good indications, but not what I hoped to find. For example, I have www.example.com?id=11
and I'd like to sh开发者_如何学Cow something like www.example.com/mike
where mike
is the user for that id.
The best solution by now is to use rewrite as:
www.example.com/11/mike
to www.example.com?id=11
I know how to write that rule, but is there a possibility to call that without the id number? Someway, to hide it?
if you wanted /mike you would have to intercept that in your code and store it as an index. So instead of doing a search on id = 11, you'd do slug = mike instead.
If you go this route you will need to make the associated field an index to prevent any unnecessary database load.
First, you're rewriting www.abc.com/11/mike
to www.abc.com?id=11
, not the other way around, i.e., the first external request is written to the second internal request, which is then processed.
To answer your question, no, unless your application knows how to fetch the object from mike
instead of 11
. If it does, you for instance could rewrite:
www.abc.com/11/mike to www.abc.com/?id=mike
or you could do it without query strings at all and read the data from $_SERVER['PATH_INFO']
, as long as your web server is correctly configured.
Not really. If you need the data passed to the script as a $_GET
variable then it has to be passed through the URL.
You can switch over to using $_POST
data instead of $_GET
, but I wouldn't recommend that. You can also just change what your script expects and user the username instead of the ID, then you'd have to pass the username (just like you want) and can drop passing the ID altogether.
精彩评论