开发者

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

开发者 https://www.devze.com 2022-12-13 13:56 出处:网络
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 开发者_如何学Gosettings(r

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 开发者_如何学Gosettings(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

0

精彩评论

暂无评论...
验证码 换一张
取 消