Hi,
I've never actually used mod_rewrite but am constantly being nudged towards it.
I have already looked at this site http://www.4webhelp.net/tutorials/misc/mod_rewrite.php for some general info - seems quite straightforward.
However, im not absolutely sure on a few things:
When a Rewriterule has been declared how do I get the data to display.
i.e.
if you currently use a method like: /index.php?mode=books&id=456 how do you "GET" $mode and $id from the url: /books/456/
Thanks.
mod_rewrite first time use [SOLVED]
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
mod_rewrite first time use [SOLVED]
Last edited by aceconcepts on Wed Feb 13, 2008 10:54 am, edited 1 time in total.
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: mod_rewrite first time use
Code: Select all
$_mode = $_GET['mode'];
$_id = $_GET['id'];
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: mod_rewrite first time use
So using mod_rewrite, ultimately you should be able do the following:
unfriendly url: /registration?client=smith&id=123 should now be able to be viewed as: /registration/smith/123
Is this right?
unfriendly url: /registration?client=smith&id=123 should now be able to be viewed as: /registration/smith/123
Is this right?
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: mod_rewrite first time use
Ok, I have done some more research.
This is what I have: (all files are in the root dir)
File: .htaccess
File: croute.php
File: index.php
My problem is that when i enter something like: http://www.site.com/some-variable it tells me that the directory does not exist!
This is what I have: (all files are in the root dir)
File: .htaccess
Code: Select all
RewriteEngine On
RewriteRule index/(.*) index.php?parameters=$1
Code: Select all
<?
$params = array();
function Router(){
global $params;
$explode = explode("/", $_GET["parameters"]);
for($i=0; $i < count($explode); $i++){
$params[$explode[$i]] = $explode[$i+1];
$i++;
}
}
Router();
?>
Code: Select all
<?php include("croute.php")?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Let's View An Article!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
foreach($params as $x1 => $x2){
echo $x1.": ".$x2."<br />";
}
?>
</body>
</html>