I am aware that one method to provide user data to web application is to use query strings. For example http://www.example.com/get-page.php?home=aaa.html
would set variable home
value to aaa.html
and this is used in script get-page.php
. Obviously, one could write anything instead of aaa.html
and it is up to web application developer to check the input. According to this thread some web servers read the filename part of the URL and direct the request to some internal function. However, both methods use query strings. Are there any other methods besides query strings which allow user to provide random data to web application in URL?
1 Answer
If your server is apache with mod_rewrite installed, then you can use friendly urls that map to real urls with the query strings then users only see the friendly urls.
Here's some code to put in .htaccess:
RewriteEngine On
RewriteRule ^section/(.*)$ /path/to/specialpage.php?section=$1 [L]
Basically what these lines do is allow one to put in a friendly URL in the format of http://example.com/section/whatever
where whatever
is any text. When executed, the URL actually being processed is /path/to/specialpage.php?section=whatever
because of the $1
which means take the value located at the position of (.*)
.
To understand the detailed meaning of .*
, you may want to look up regex (regular expressions).