I have a site of type LP, when clicking on the links in the menu, the scrolling scrolls to the corresponding block. And URLs in look like this: http: // site / city / interiors . Did url-s with: history.pushState. Those. All clicks in the menu are saved in the browser history.

I need to make it so that when I switch from the browser’s history, the index page of the site index.php is launched.

I tried to do this:

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

But in this case, like index.php works, but css styles, images, videos are not loaded - in general, the site does not work.

Then he tried this:

 AddType "text/html; charset=utf-8" .htm .html AddDefaultCharset utf-8 PHP_VALUE default_charset utf-8 RewriteEngine on RewriteCond %{HTTP:Accept-Language} (en|ru) [NC] RewriteBase / RewriteRule ^/([a-zA-z_-]+)/([a-zA-z_-]+)$ index.php?city=$1&block=$2 

But it does not work, the launch of index.php does not happen: Error 404 Tell me how to fix this?

Another important point: if the url: http: // site / admin , then redirected to index.php, which should not occur at the root of the site.

    2 answers 2

    I tried to do this:

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

    But in this case, like index.php works, but css styles, images, videos are not loaded - in general, the site does not work.

    And css styles are not loaded as they are also redirected to index.php

    You need to make a rule for styles, like this:

     RewriteRule ^/css/(.*).css$ css/$1.css [L,QSA] 

    And put it higher than the general rule.

    • It turns out that this rule I need to register for each css and js file? - amijin
    • Why it does not work. Tell me, why does the second option I described not work? It would be great for me if it worked. I, in that case, would be able to process the GET parameters when loading the site from the browser history - amijin
    • Using your advice, I get this: if the url was originally " domain / city / interiors, then when you go through it, you get:" domain / city / css / jquery.ui.slider.css " - amijin
    • And if you leave only 1 parameter after the domain, then everything works, for example: domain.ru/city - amijin
    • This rule will only work if it starts with / css / and ends with a .css address. Those. for domain / city / interiors there will be a redirect to index.php? city / interiors. For js, you can write in the same way as RewriteRule ^ / js /(.*.) Js $ js / $ 1.js [L, QSA] As to why your second option does not work, I can’t say anything. - Victor Evlampiev

    And what prevents to register readfile for CSS and other files directly in index.php? Personally, I do, in my opinion it is beautiful and logical. All the same, htaccess is an Apache configuration file, not the web application itself. In addition, php is very convenient to register all the necessary http headers :)

    • If I knew how to do it right ... but I'm not a Jedi :( - amijin
    • @amijin Then I advise you to take a ready-made solution, some kind of Joomla :) - user208916