Reputation: 340
I am working on a project and i am putting SEO in mind, the smartest way around this will be to dynamically create a none existing page.
Details
i have a list of towns
This are links that look like http://xxxxx.com/texas
**Note:**there is no file named texas.php
I have a template page that fetches from the database base on the town clicked on.
I want the link to look like this http://xxxxx.com/schools-in-texas
That should display a page with the template showing results from database after querying the DB with the work "texas"
this should apply for other towns e.g http://xxxxx.com/schools-in-toronto
Upvotes: 2
Views: 66
Reputation: 5664
First you should route any Not Found pages to a php script.
In you .htaccess
file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Then you can get the URL as a string and get the part you need.
for example if you visit yoursite.com/Texas the following script will return /Texas
:
<?php
echo $_SERVER[REQUEST_URI];
and you can do any further work on database...
(The htaccess code got from the Laravel's)
Upvotes: 1
Reputation: 3466
You have to use apache's mode-rewrite rules. With that you could parse your URL and set your GET-String parameters to be used in your controller file that is responding to your page request.
Here is a simply tutorial: Mod-rewrite tutorial
Upvotes: 1