The actually URL which my app uses is:
http://site.com/search.php?search=iPhone
but I would like it to be possible to achieve the same with
http://site.com/iPhone
I have no experience of rewrite rules, how can I set this up?
The solution has worked but the new URL is displayed in the address bar. I thought it would have been possible to set this up so that it appears as though the page location is
http://site.com/iPhone
without changing to display
http://site.com/search.php?search=iPhone
Is this possible? Thanks.
You need to specify something like this in your .htaccess file:
Check also:
Create a file called .htaccess in the root of your website and put this in it.
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
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.
Rewrite rules aren't part of PHP as far as I'm aware, but Apache (specifically
mod_rewrite
) or whatever server you're using. For Apache, you need on the server to have a file called.htaccess
, and in it put something like:^(\w+)/?$
is a regular expression - it matches any word of 1 or more characters, followed by a/
maybe. So it changessite.com/iPhone
intosite.com/index.php?search=iPhone
. Sound about right?