UnknownPlayer Posted August 3, 2011 Share Posted August 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/ Share on other sites More sharing options...
cags Posted August 3, 2011 Share Posted August 3, 2011 RewriteCond's only apply to the RewriteRule directly following them, thus only your first rule applies if the files don't exist. The second rule will apply regardless of it's existence. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1251426 Share on other sites More sharing options...
UnknownPlayer Posted August 4, 2011 Author Share Posted August 4, 2011 But my address for images is now http://localhost/freeoglasi/kategorije/1/cars/images/plug.gif and it need to be http://localhost/freeoglasi/images.plus.gif can i make rewrite to be disabled for image filder ? Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1252201 Share on other sites More sharing options...
cags Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1252375 Share on other sites More sharing options...
UnknownPlayer Posted August 7, 2011 Author Share Posted August 7, 2011 Yes, i mean src attr at img tag, and image path in code is "images/plus.gif". So, how do i need to put path ? Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1253676 Share on other sites More sharing options...
cags Posted August 7, 2011 Share Posted August 7, 2011 assuming images is in your root... "/images/plus.gif" Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1253681 Share on other sites More sharing options...
UnknownPlayer Posted August 7, 2011 Author Share Posted August 7, 2011 But when i am trying to test my code on my localhost "/images/plus.gif" does not work, is that becouse my folder is http://localhost/up/ ? That is root of my code.. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1253854 Share on other sites More sharing options...
cags Posted August 8, 2011 Share Posted August 8, 2011 Yes, it is. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1254094 Share on other sites More sharing options...
UnknownPlayer Posted August 8, 2011 Author Share Posted August 8, 2011 Ok thanks.. But can i use some other solution for this? Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1254145 Share on other sites More sharing options...
cags Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1254411 Share on other sites More sharing options...
UnknownPlayer Posted August 8, 2011 Author Share Posted August 8, 2011 I use constant just like u wrote, but how can i use that constant in .js file ? Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1254469 Share on other sites More sharing options...
cags Posted August 8, 2011 Share Posted August 8, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1254477 Share on other sites More sharing options...
UnknownPlayer Posted August 10, 2011 Author Share Posted August 10, 2011 Thanks.. this is good.. Quote Link to comment https://forums.phpfreaks.com/topic/243718-problem-with-images-directory-and-cat-name-this-way/#findComment-1255488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.