There is one index.php, and url like http://domains.ru/city/stock . It is necessary that when entering the site through a similar url (after the domain name there can be only 1 or 2 parameters, the names of the parameters are any) the user gets at index.php, which is in the root of the site. It was done like this:

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

We enter http://domains.ru/city/stock and get index.php without styles and in the console I see an error:

 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domains.ru/city/css/style.css". 

Tell me how to fix it?

  • Why do you need this RewriteRule ^css/(.*).css$ css/$1.css [L,QSA] line? She redirects to the same address that was called. Yes, and not existing files (previous RewriteCond just refer to this redirection, and not to the second RewriteRule ). - Visman pm
  • I hoped that this line would load the styles. Even if I remove this line, then index.php is still loaded without styles - amijin
  • You specify the https protocol at the site in question. Do your stylesheet also download the https protocol? - Visman
  • the protocol is specified by mistake, while I test the site locally using openserver - amijin
  • The styles you have are not here http://domains.ru/city/css/style.css , and here http://domains.ru/css/style.css ? If yes, then write in the templates is not a relative path to the styles, but absolute. - Visman

2 answers 2

If you want to leave relative paths to styles, try these rules:

 RewriteEngine On RewriteRule /css/([^\/]+).css$ css/$1.css [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L,QSA] 
  • standards, styles are tightening :) here, only images and fonts during layout were also indicated in relative paths :( Tell me why, if I specify only one parameter after a domain name, for example: domains.ru/city , then everything loads fine, but if two parameter, for example: domains.ru/city/stock , then nothing loads? ( - amijin
  • Do not use relative paths, then they are relative. Here is the answer to all your problems. - Visman pm

Remove this condition

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

In the template, specify a direct path to css. <link rel="stylesheet" type="text/css" href="/css/style.css">

  • The site is fully working and all styles are written in a template. I removed the specified rule line, but this did not solve the problem. - amijin
  • Opening the domains.ru/city/stock page , the browser believes that it is located there, no matter what the script actually handles. If the style is registered as css / style.css, then it will look for it on domains.ru/city/stock/css/style.css and not where it is physically located. Therefore, in the case of any CNC specify absolute paths. - iosp