Good day to all. Imagine site addressing:

http://site.ru/?theme=questions http://site.ru/?theme=tags http://site.ru/?theme=users http://site.ru/?theme=badges 

The topic in the section, say, some divisions on the content yet, is an additional variable

 http://site.ru/?theme=tags&tags=tema_1 http://site.ru/?theme=tags&tags=tema_2 

Everything is simple and clear, we determine the value of the variable, we display the necessary content on the site. now about the incomprehensible:

 http://site.ru/questions/ http://site.ru/tags/ http://site.ru/users/ http://site.ru/badges/ 

Then the puzzle begins, if you want to share the content more ...

 http://site.ru/questions/vopros_1/ http://site.ru/questions/vopros_2/ http://site.ru/questions/vopros_3/ 

The first thing that comes to mind is a separate directory, and there still need to push. Htaccess. But then, let's say, you have to make a link to a style sheet tied to the site address, and not the directory.

The second - the address of the line is divided into parts. A certain part is equal to a certain variable.

Third, I don’t know something 8- (

  1. How is it possible to simply equate an address from a line of an address to a variable on php? Is it possible to do this only in php?
  2. Are there any advantages in the second method I described?
  3. Maybe I do not understand something?
  • 2
    About mod_rewrite rumors did not reach? =) - Palmervan
  • ingenious. I'll start digging in this direction. thank. - sergey
  • Well, yes ... I'll just shut up. - Artem

1 answer 1

Here is my example, implemented through parsing REQUEST_URI

.htaccess

 Options +FollowSymlinks RewriteEngine On # Если не файл RewriteCond %{REQUEST_FILENAME} !-f # Если не директория RewriteCond %{REQUEST_FILENAME} !-d # Запускаем index.php RewriteRule (.*) index.php 

index.php

 <?php function ParseURL_ModRewrite() { //Чиста URI $uri=preg_replace('#[a-z0-9]+\.[a-z0-9]+$#i', '', $_SERVER['REQUEST_URI']); $get_reqs=explode('/', $uri, 20); for($i=0;$i<sizeof($get_reqs);$i++) { if($get_reqs[$i]=='' && ($i+1)==sizeof($get_reqs)) break; $_GET['value'.($i+1)]=$get_reqs[$i]; } } ParseURL_ModRewrite(); //Вывод на экран всех параметров GET print_r($_GET); ?>