How to create dynamic pages with .htaccess and mod_rewrite
I want to know what I need to put in the .htaccess to do the following.
When people call one of my pages, for example:
http://www.mydomain.com/cooks/New-York_NY.html
http://www.mydomain.com/cooks/Plantation_FL.html
that i开发者_C百科t would create these pages on the fly from a file called cookscities.php
.
Then the page cookscities.php
would pull the values from the URL for the city and state and place it on the page.
So for sample requested page: http www.mydomain.com/cooks/New-York_NY.html
my page cookscities.php
inserts value of URL on page content city value but remove the "-" if there is one and also places the state 2 letters.
So the page title would say:
Find Cooks in New York NY
In .htaccess add:
RewriteEngine on
RewriteRule /cooks/(.*)$ http://mydomain.com/cookscities.php?val=$1 [L]
This matches any URL beginning with /cooks/ and calls cookscities.php, passing in the part after "/cooks/" as the GET variable val
.
In cookscities.php you could have:
<?php
list($city, $state) = explode('_', $_GET['val']);
$city = str_replace('-', ' ', $city);
echo "Find Cooks in $city $state";
?>
This is usually done by using mod_rewrite: http://www.sitepoint.com/guide-url-rewriting/
精彩评论