How to hide subfolder when rewriting urls

My website: www.mysite.com/subfolder/login/index.php

I want the url to be only www.mysite.com/login/index.php . I tried changing the .htaccess file in the root folder as follows:

 RewriteRule ^login\/index\.php$ /subfolder/login/index.php [L] 

- but the problem is that then he cannot use or access the CSS file (style.css) from the login folder.

+1
source share
3 answers
 # fix js/images/css RewriteRule ^.+?/((img|css|js)/.+)$ /subfolder/login/$1 [L,NC] 

Try adding this as the first rule in htaccess . Or you can use

 # fix js/images/css RewriteRule ^.+?/((img|css|js)/.+)$ http://www.yourdomain.com/subfolder/login/$1 [L,NC] 

Here you can see more examples and ways to rewrite: https://wiki.apache.org/httpd/Rewrite

+1
source

Add another rule for css or use an absolute CSS path for example :.

 RewriteRule login\(.*)\.css /subfolder/login/$1.css [L] 
0
source

The name does not seem to correspond to the question at the end of your description, but to answer the last: if you have problems with your resources (images, css, external javascript, etc.) after rewriting the URL, use the absolute path, for example:

 /subfolder/login/style.css 

instead of something like:

 ../style.css /* this will probably not work when rewriting urls */ 
0
source

Source: https://habr.com/ru/post/953199/


All Articles