The first thing to do with this module is making it on.
Type this code in .htaccess file:
RewriteEngine on
Example 1:
To make a practice, please make a two file in the directory that same as .htaccess file (one.php and two.php). Then write in your .htaccess file:
RewriteEngine on
RewriteRule ^one\.php$ two.php
Then try to browse http://localhost/one.php
Whay you really get is the content of two.php file, not one.php file.
Example 2:
Create a index.php file
<?php
$name = $_GET['name'];
$name = !empty($name) ? $name : "No Name";
?>
<h1>Your Name: <?php echo $name; ?></h1>
Then create an .htaccess file:
RewriteEngine on
RewriteRule ^([a-z])+$ index.php?name=$1
Browse http://localhost/luna
To make a match of three arguments - name, gender and city - use:
RewriteRule ^([a-zA-Z]+)\/([a-zA-Z]+)\/([a-zA-Z]+)$
index.php?name=$1&gender=$2&city=$3
RewriteRule ^([a-zA-Z\s]*)$ index.php?name=$1 // space
No comments:
Post a Comment