473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

.htaccess path problem

28
dear all,

I would like to ask about url rewriting in php. One of my project I got a problem
with image path.

.htacess
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home/?$ index.php
RewriteRule ^product/([0-9]+)/?$ product.php?prd_id=$1 [NC,L]
I am using header.html as a common file. But the images from header.html only display in index.php. In product.htm none of image can't display. I think I have a problem in .htacess file. Please let me know about this.
Mar 19 '09 #1
5 9861
i think you are using relative link for images. Try using absolute path for images, hope u wil solve ur problem
Apr 8 '09 #2
Atli
5,058 Expert 4TB
Hi.

You need to be very careful with images, and other resource paths, when using mod_rewrite.

What you need to keep in mind is, the images are requested separately.
So, if a user requests: http://example.com/home/
And you have a rule: RewriteRule ^home/?$ index.php
The request will be routed to: http://example.com/index.php

However, any additional resources, like images, in that page will not be rerouted by that rule.
Meaning, if that page includes an <img> at: images/header.jpg
The request will be: http://example.com/home/images/header.jpg
Which will not be rerouted by your original rewrite rule.

If you want the image path to be re-written as well, you need to add a rewrite rule for that to. (Or come up with one that covers both)

A simpler way, as rayckins suggested, would be to use absolute URLs for all resource links.
Meaning: /images/header.jpg
Rather than: images/header.jpg

The added / to the link simply means that it should start at the web-root, rather than the current location.
Apr 18 '09 #3
raamay
107 100+
@Atli
I am also with the same problem and has been wondering how to make it work. Well i am not sure about how to rewrite the image,css & js path in htaccess but i can say little about the absolute path you are referring to. Well, adding a slash in the infront doesnt solve the problem. Only if you use the entire long absolute path then it works something like href="http://localhost/mysite/images/image1.gif". And if we start using absolute path in all our hrefs i must say its not manageable for big sites.

So, i feel there should be some way to use relative paths only. Or it can be done via the path rewriting method in htaccess. I tried this way but couldnt make it work href="<?php echo $_SERVERDOCUMENT_ROOT."images/image1.gif"; ?>".

Anyone can please tell us how to rewrite the path of these files aswell in htaccess.
Apr 19 '09 #4
raamay
107 100+
I found a solution for the path problem. I think you were using relative path for refering to image, css and js files.

ok define a constant variable in your page something like
Expand|Select|Wrap|Line Numbers
  1. define("ROOT_DIRECTORY", "\your root directory\"); 
to store the path of your root directory. Then whenever you want some image or css or js files to be used in your page you can do it in this way
Expand|Select|Wrap|Line Numbers
  1. href="<?php echo ROOT_DIRECTORY; ?>your image directory/image file"
.

But remember here that the constant ROOT_DIRECTORY should have a value of absolute path. If i am to give you an example, I am using WAMP, so i will give you the wamp example. My files are stored under the www directory of wamp i.e C:\wamp\www\mysite folder. So now when i use absolute path i have to use \mysite\ as the root. Now, i will write my root_directory constant as
Expand|Select|Wrap|Line Numbers
  1. define("ROOT_DIRECTORY", "\mysite\");
I have a image folder inside mysite folder. Now if i want to use a image i will reference it in this way
Expand|Select|Wrap|Line Numbers
  1. href="<?php echo ROOT_DIRECTORY; ?>image/image.gif"
This will make sure that correct path is specified in any page whose url is rewritten.

Hope this helps you. I also had the same problem as yours but i was able to solve it today following the above method.
Apr 19 '09 #5
Use <base href="http://www.yoursite.com/yourfolder/" /> to fix this problem.
Sep 30 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: hokiegal99 | last post by:
I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 computer. When I write a Python script and run it from the command prompt, I get the following error: C:\>python...
1
by: William Starr Moake | last post by:
Another problem with absolute paths in the WYSIWYG editor I'm putting together. The function to toggle between WYSIWYG and HTML modes works except for one glitch. If you use a relative path for...
4
by: gnah | last post by:
Greetings, I hope my problem is easy to fix, I'm pretty new with php - but I am getting weird results with the opendir() function. It may just be a path problem, but I don't see which variable...
4
by: Tim | last post by:
Hello, i try to write some data into an XML-file via c#. When I specify the path like "c:\\temp\\test.xml" the XmlTextWrite could open the file. But when I tried to get the path from...
3
by: route_coder | last post by:
I am using access database to create a crystal report in VB.NET Everything works fine when I run on my machine. But when I am deploying it other windows machines. It is asking for database server...
9
by: Pumkin | last post by:
Hello guys, I have a small problem with setting the absolute path of an image. Here is the scenario: I need to put the image in a text concat something like this: <asp:Label id = "lbl"...
1
by: gnewsgroup | last post by:
I have a user control called Footer.ascx, in which a background image is inserted like so: <div id="footerdiv" style="background-image:url('Images/ mybackground.jpg');...
1
by: Maanav Jackson | last post by:
Hi I am displaying a third party webpage into a variable using curl library. When i am displaying the variable in the browser using echo command as shown below. echo $pagecopy; Browser is...
10
by: Raheem | last post by:
Hello, I built a development version of a live website on my hosted account. However the development version is having problems with finding include files. After troubleshooting I was able to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.