skip to Main Content

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

  1. Texas
  2. Delhi
  3. Toronto
  4. Sydney

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

2

Answers


  1. 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)

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search