.htaccess URL Rewrite Problem (Scripts not loading)

I am having a problem with rewriting urls in .htaccess.

Here is my rewrite code :

RewriteEngine on
RewriteBase /

RewriteRule     ^terms(.*)  terms.php [L,nc]
RewriteRule ^formgate\/([a-zA-Z0-9]{64,64})$ formgate.php?g=$1 [L,nc]

When the page loads, it works correctly, except that all my stylesheets, javascript files, etc. not loading properly. If you check for errors that say 404 is not found and that $ is not defined. Thanks

+3
source share
1 answer

This issue is often related to using relative URLs in javascript styles or files and combining them with a virtual directory structure. If you have a rewrite like this:

RewriteRule ^articles/(.*)$ articles.php

Then you have the url:

http://example.com/articles/2011/03/14/title-of-the-article

which contains HTML:

<link rel="stylesheet" type="text/css" href="css/general.css" />

, artices.php -, , mod_rewrite . :

http://example.com/articles/2011/03/14/title-of-the-article/css/general.css

, , . URL- -. :

<link rel="stylesheet" type="text/css" href="/css/general.css" />

/ theURL.

: URL- /, -. directurey:

/
    /index.html
    /afolder
        /afolder/stylesheets
            /afolder/stylesheets/first.css
            /afolder/stylesheets/second.css
        /afolder/images
            /afolder/images/a.jpg
    /otherfolder
        /otherfolder/something.html
+4

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


All Articles