views:

437

answers:

2

I was wondering if I could process an URL without specifing parameters. For example: http://www.example.com/Sometext_I_want_to_process

I don't want to use: http://www.example.com/index.php?text=Sometext_I_want_to_process

The site has to redirect to a different page after processing.

What language choice do I have?

A: 

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 ;-)

Pascal MARTIN
+3  A: 

I would suggest using apache's mod_rewrite (similar functionality is found on other webservers) to rewrite the URL so that it is a parameter. For instance with the text parameter you use, you could use the following mod_rewrite rules to get the parameter.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico # Want favicon.ico to work properly
RewriteRule ^(.*)$ index.php?text=$1 [L,QSA]

Then you simply access the parameter in the script like you normally would.

<?php     
$stuff = $_GET['text'];
// Process $stuff
codeincarnate