You can do that kind of thing using Apache's mod_rewrite
.
Obvisouly, it means it must be enabled -- which is too often not the case by default.
For instance, on a website, I use this in a .htaccess
file :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php?hash=$1 [L]
This redirects everything, like www.mysite.com/152
to www.mysite.com/index.php?hash=152
And, then, in my PHP code, I can just use $_GET
:
if (isset($_GET['hash'])) {
if (is_numeric($_GET['hash'])) {
// Use intval($_GET['hash']) -- I except an integer, in this application
}
}
In your case, you'll probably want to replace "hash
" by "text
", but this should already help you getting closer to the solution ;-)