.htaccess - Friendly URL affects image paths and js

0

I explain:

My website without friendly URL is like this

link

and my images and js work perfect

src="img / image1.png"

src="js / script.js"

The error comes when I have friendly URLs

link

Because the DOM takes me the routes of the images and js asi:

link link

Obviously gives the error.

and I know how to solve it by putting the URL of the web. or putting ../../

But the thing is not there I'm tired of being the same in every project.

SO I LOVE THE SOLUTION WITH PURE HTACCESS. Can someone help me?

PS: I want it to be relatively achievable, since this script is installed in several domains and I do not want to be configuring URLs for each different domain.

This is the code that I have in my htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# idiomas web.com/es/   web.com/en/   web.com/br/
RewriteRule ^([a-zA-Z]{2})/?$ index.php?lang=$1
    
asked by John 28.06.2016 в 02:36
source

2 answers

1

What you can do is put absolute routes, and to be worth for several domains, is to get the domain name with php. Example:

$nombreDominio = $_SERVER['HTTP_HOST'];

And to put the routes like this:

src="<?php echo $nombreDominio; ?>/img/imagen1.png"

I hope it serves you

    
answered by 28.06.2016 в 07:12
1

Something like this to prevent a directory from moving:

RewriteCond %{REQUEST_URI} !^/img/.*$

It would be better if you put the content of your current .htaccess in your question.

Edit: I see, it's more complicated than I thought. You can do something like this:

RewriteCond %{REQUEST_URI} ^.+/(img|js)/(.+)$
RewriteRule . /%1/%2 [R]

Any URL that contains /img/ or /js/ is redirected to /img or /js plus the rest. So:

httpx://dominio.com/loquesea/valor/img/imagen1.png
httpx://dominio.com/loquesea/valor/js/script.js 

they come back:

httpx://dominio.com/img/imagen1.png
httpx://dominio.com/js/script.js
    
answered by 28.06.2016 в 03:16