Reputation:
What would be the htaccess rule of the following case:
I redirect my user to this page:
system/abc123/step1
Without a rule it could be:
system.php?id=abc123&step=step1
But how can I get via $_GET
the two parameters passed ?
abc123
step1
Thanks a lot.
Upvotes: 2
Views: 38
Reputation:
What I was looking for is :
In my .htaccess:
RewriteEngine on
RewriteRule ^system/(.+)/(.+)$ system?token=$1&step=$2 [L]
In my system.php page:
$QUO_Token = $_GET['token']; // abc123
$QUO_Step = $_GET['step']; // step1
Upvotes: 1
Reputation: 11689
Your own solution is fine, and it works as expected, without touching php code.
However, for my scripts I adopt a different approach:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /processUrl.php [NC, L]
By this way, ALL (Not Foud) incoming requests all redirected to processUrl.php, in which there is a code like this:
$uri = (object) parse_url( $_SERVER['REQUEST_URI'] );
$uri->thread = explode( '/', substr($uri->path, 1) );
if( 'system' == $uri->thread[0] )
{
$_GET['id'] = $uri->thread[1];
$_GET['step'] = $uri->thread[2];
include( 'system.php' );
}
elseif( 'browse' == $uri->thread[0] )
{
// Other condition here
}
elseif( isset( $uri->query ) )
{
// Process ORIGINAL $_GET
}
else
{
include( 'Your404NotFoundPage.php' );
}
I prefer the above method due to:
Upvotes: 0