PHP Rewrite Rules

Create a file called .htaccess in the root of your website and put this in it.

RewriteEngine on 
Options +FollowSymlinks
RewriteBase / 

RewriteRule ^(.*) search.php?search=$1 [R]

Should do the trick.

I would suggest however that you make it a bit more specific, so maybe require the user of a search directory in your url. eg instead of mysite.com/IPhone use mysite.com/search/IPhone which would work like

RewriteEngine on 
Options +FollowSymlinks
RewriteBase / 

RewriteRule ^search/(.*) search.php?search=$1 [R]

This makes it easier to have normal pages that arnt redirected, such as about us or a basic homepage.

As Chris says, this is not PHP but Apache that does this, and whether it works can depend on your hosting setup.

Leave a Comment