mod_rewrite $_GET

前端 未结 2 856
醉梦人生
醉梦人生 2021-01-27 03:47

I have a FrontController expecting two $_GET params:

controller
action

A typical call to the site would look like thi

2条回答
  •  醉梦人生
    2021-01-27 04:26

    There are 2 parts to getting this working. If you are working with PHP and Apache, rewrite engine must be available on your server.

    In your user folder put a file named .htaccess with these contents:

     RewriteEngine on
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule . index.php [L]
    

    Then your index.php you can use the REQUEST_URI server variable to see what was requested:

    
    

    If someone requested /start/register, then assuming all the above code is in the html root, the $path variable would contain start/register.

    I'd use the explode function on $path using the / as a separator and pull the first element as register.

    The rewrite code has the benefit of working with filenames and directory names.

提交回复
热议问题