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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.