Thursday 15 April 2010

.htaccess - PHP pass url to index.php -


It should really be simple, but I want to be able to use the URL as a variable such as php frameworks .

  mywebsite.com/hello-world   

Let me see my index.php as a variable "hello-world" and give me index Should load .php Is it done via PHP or do I have to use an HTXus file?

Use several PHP frameworks urls to send messages to the pointer file ... For example ...

 

There are two steps :

  1. Rewrite the URL using a .htaccess file (on Linux) You need to make sure that all the requests will go to your PHP file so that You can get all the files from your existing files and folders into your PHP file Have to write again;
  2. You analyze URLs in your PHP file, for example, depending on the $ _ SERVER ['REQUEST_URI'] ) and its contents.

    For step 1. You can use something like this:

      RewriteBase / RewriteCond% {RewriteEngine currentREQUEST_FILENAME}! -f RewriteCond% {REQUEST_FILENAME}! -d RewriteRule ^ (. *) $ Your_file.php? Url = $ 1 [L, QSA]   

    and then in step 2 in your php file. You have the url requested in $ _ GET ['url'] . Edit :

      Rev. ^ ^ sub / dir / to / relight / (*) $ your_file.php? Url = $ 1 [L, QSA]   

    Some details:

    • ^ (. *) $ Start ^ and end $ capture everything (all the characters) They are captured using brackets so that you can use them in a query string such as $ 1 . In the edited example, only section has been received since .... / rewrite / ;
    • The option between [...] means that this is the last rule for the L process and QSA The original query string has also been added to the new URL. This means that if your url / hello world is some_var = 4 that the some_var variable is added again with the url written? your_file.php url = Hello - World & amp; Some_var = 4 .

No comments:

Post a Comment