简体   繁体   中英

Using URL contents to send data(post or get) to a PHP page

OK, I am creating a questionnaire application that is managed by a single user on /manage. There, he can create multiple questionnaires, each with a different name and set of settings(registered users, questions, data, etc.). Currently, the different tests are accessed by non-administrative users(the takers of the test) by going to /index.php?t=Questionnaire%20Name. Obviously, this is not the best interface to give to users. I would like for the users to be able to access that test by going to /QuestonnaireName. I feel like this could be done with mod-rewrite, but I don't know how to use it or where to start. I've coded the entire thing in JS, PHP, and MySQL. Any help is appreciated. Thanks.

Here's a example to get you going:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

Put this in a file called .htaccess in the same directory as index.php. Now everything you call will be routed to index.php, and you can get hold of the url with $_SERVER['QUERY_STRING'] . Then you are free to do anything you want with it.

Alternative way, to save you from making edits to index.php:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?t=$1

Notice the t= after the index.php? . Now everything can be found from $_GET['t'] , but I can't guarantee this will be foolproof as I have not used this method myself. Test it out and see if it works for you.

EDIT

Edited to allow access to physical directories.

You have to use mod_rewrite:

Example of use (it is german, I did not found any better solution): http://www.handcode.de/talks/phpug-mod_rewrite-20080312/slide-38.html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM