matt 0

How can I use a /whatever instead of a /this?w=whatever in my site.


instead of:

and be able to do things (look up in sql database) with that string

2 answers


If you're on Apache, use mod_rewrite, either in the apache.conf file or in your .htaccess file if you're on shared hosting. Here's a readable introduction.

Answered over 9 years ago by Rob Crowther

Like Rob said. I'll add some mod_rewrite example though:

so let's say you have this url:

and you want this:

You'll need to open the httpd.conf file and write the following.

<IfModule mod_rewrite.c>
  RewriteEngine on  # activates the rewrite engine
  RewriteRule /search/([a-z_]+)/ /search.php?s=$1

there's 2 important part in the RewriteRule line.

  1. /search/([a-z_]+)/ : This means "keep in mind more than 1 small letter from a to z including the _ after /search/
  2. /search.php?s=$1: This part means: "Redirect that to search.php and add a S get parameter with the part I asked you to keep earlier"

It's hard to get it right at first so don't try it on a production server. I always test my rewrite rule in my dev environment first. Go read that intro now :)

Answered over 9 years ago by Bernard Chhun