Now I am going to discuss about this problem.
Problem: Redirect a unknown url address to a known url address.
Description of the Problem: When one write an address in the browser's address bar it shows some information from the file belongs in that address. like when I write in address bar "http://kolorob.info/kolorob/" or "http://kolorob.info/kolorob/index.php" it can show the specific page because this page is physically or dynamically exists. But when I write "http://kolorob.info/kolorob/post/26" browser starts to find a folder named "26" from another parent folder "post". But these folders are not exist physically or dynamically. If I want to show the 26th post to browser I need to get the information from the url to any of my existing page. I need the type of material ("post") and the number of that type of material to show the user.
Solution:
Need to add the following line to the .htaccess file of the folder where the project is situated.
RewriteEngine on
RewriteRule ^(./*)$ index.php [QSA,L]
The code shown above will help the url like ("http://kolorob.info/kolorob/post/26") to be redirected to "http://kolorob.info/kolorob/index.php" and it will bring the asked url by a global variable $_SERVER['REQUEST_URI']. Now one can easily get the whole url that was requested by user in "index.php". This url could be broken into pieces with the explode function of PHP using delimiter ("/"). Then the pieces are found "post", and "26". Index.php can easily recognize the type of material ("post") to be shown and the number of that type of material (26th post).
No comments:
Post a Comment