CSS and JavaScript files do not load when using Amigavel URL

0

Hello,

I'm trying to create Friendly URL and it worked fine on some pages only some of it is not working CSS, JS etc.

I'm using this in .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^home/?$ /index.php?p=home [NC,L]

  RewriteRule ^sign_in/?$ /index.php?p=sign_in&action=get-in [NC,L]

  RewriteRule ^sign_up/?$ /index.php?p=sign_up&action=new-user [NC,L]

  RewriteRule ^ranking/([0-9]+)/?$ /index.php?p=ranking&c=$1 [NC,L]

  RewriteRule ^item/([0-9]+)/?$ /index.php?p=topic&id=$1 [NC,L]

</IfModule>

The home pages, sign in and sign up worked right the CSS the JS etc loaded .. now on page ranking and item did not load CSS and JS, then I gave an Inspect element and CSS and JS did not work because is not in the 'ranking' folder, then I ask you, I'll have to create a 'ranking' and 'item' folder and add all the files that already exist again in these folders (all the files I speak to the css folder containing the files and the js folder that is the javascript)?

    
asked by anonymous 02.01.2016 / 06:44

1 answer

3

The simplest way to resolve static links is to define the HTML tag

<base href="http://endereço.base-do-seu.site/">

Another way is to set the absolute path in all links (href, src) or the correct pointing to the base path if you want to maintain relative paths.

Example of absolute path (absolute path): http://endereço.base-do-seu.site/css/styles.css

Relative path example (relative path): /css/styles.css

Note the difference in the assembly of relative paths

When starting with slash (/), the base will be the root folder, that is, it is the same as pointing to http://endereço.base-do-seu.site/ .

If you do not specify the base, the links point to several base paths. Example:

Suppose the page is in http://endereço.base-do-seu.site/pasta . If CSS is pointing to css/styles.css , it's like linking to http://endereço.base-do-seu.site/pasta/css/styles.css .

For this example case, you can resolve by doing directory indentation or setting a base explicitly by the HTML tag or absolute path.

obs: We are talking about links to CSS and JS, however, this applies to every type of link.

    
02.01.2016 / 07:02