Jump to content

Problem with images directory and /cat-name/ (this way)


UnknownPlayer

Recommended Posts

I have this .htaccess code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(kategorije|artikli)$ ./$1.php [L,QSA]
RewriteRule ^kategorije/(.*)/(.*)$ ./kategorije.php?q=$1/$2 [L,QSA]

 

Now when i go to:

http://localhost/freeoglasi/kategorije - all images works fine.. everything is good, and in js code i have function which set image src on place with folder images/plus.gif

But when i go to:

http://localhost/freeoglasi/kategorije/1/cars - all images on page works, when it is loaded, becouse i use full address + images/image-name.gif but in js i still use images/plus.gif and that doesnt work, so can i make exception for image files and foldes in mod_rewrite?

What do you mean that the address for your images is now "http://localhost/freeoglasi/kategorije/1/cars/images/plug.gif"? Do you mean that is the value that's in the src attribute of your image tag? If so then your problem isn't your rewrites directly it is your script, and you need to change the paths you are putting in the src attribute.

Use a full URL, domain inclusive. A common solution in Frameworks is to set a variable / const at the start of your landing page using something along the lines of...

 

define('ROOT_URL', basedir(__FILE__));

 

Basically you need to store a value in root that's accessible from wherever you need to output a path.

You can't, without serving your js files with PHP. A simple solution would be to simply add them in a JS block in your document head as variables, these will then be available in your other scripts.

 

<script type="text/javascript">
var ROOT_URL = '<?php echo ROOT_URL; ?>';
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.