PHP Rewrite Rules

前端 未结 3 921
心在旅途
心在旅途 2020-11-30 06:56

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 wit

3条回答
  •  无人及你
    2020-11-30 07:39

    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:

    RewriteEngine on
    RewriteRule ^(\w+)/?$ /index.php?search=$1
    

    ^(\w+)/?$ is a regular expression - it matches any word of 1 or more characters, followed by a / maybe. So it changes site.com/iPhone into site.com/index.php?search=iPhone. Sound about right?

提交回复
热议问题