Hello. How to implement the function so that .htaccess redirects the user from an address like http://mysite.ru/var1/ to http://mysite.ru/index.php?page=var1. Thank.

    3 answers 3

    RewriteEngine On RewriteRule (.*)\/ http://mysite.ru/index.php?page=$1 [R,L] 

    Will throw http://mysite.ru/var1/ to http://mysite.ru/index.php?page=var1, and the page at http://mysite.ru/var2/ to http: // mysite. ru / index.php? page = var2

    Update

    Add immediately after RewriteEngine on

     RewriteRule switcher.php - [L] 

    Update

    Can so

     RewriteRule \.\*\\.php\.* - [L] # for any .php file do nothing 
    • I have all the styles and scripts from the content of the document also began to be cut by this code. )) - Glorymirror
    • A new problem has appeared, now all links on the page lead to the index page. Ie all requests via ajax return the index page - Glorymirror
    • Give an example of the link and describe how it should work. - Get
    • Suppose I turn on site.ru/switcher.php?pagen=history. It should return the text, and return the source code of the index file. - Glorymirror
    • Do I have to add each file like this? - Glorymirror

    @Glorymirror , in theory, this modification will help:

     RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f # Исключает файлы из совпадения RewriteRule (.*)\/ http://mysite.ru/index.php?page=$1 [R,L] 
       Redirect var1/ http://mysite.ru/index.php?page=var1 
      • If the variable is constantly changing, how will this work? - Glorymirror
      • use urlrewrite - MarinaVoyin