matt 0

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

ex:

twitter.com/user

instead of:

forum.com/search?do=getnew

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

2 answers

1
point

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 almost 7 years ago by Rob Crowther
0
points

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

so let's say you have this url:

myforum.com/search.php?s=foo

and you want this:

myforum.com/search/foo

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
</IfModule>

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 almost 7 years ago by Bernard Chhun