473,836 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.htaccess path problem

28 New Member
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 9882
rayckins
1 New Member
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 Recognized Expert Expert
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 New Member
@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 $_SERVERDOCUMEN T_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 New Member
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\mys ite 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.co m/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
4352
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 'name-of-script.py' 'python' is not recognized as an internal or external command, operable program or batch file. Here's what my path contains:
1
3121
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 a link, like <a href="download.htm">Click Here</a>, the editor returns an absolute path the second time you toggle HTML mode: <a href="C:\Windows\Desktop\Editor\download.htm" and even adds file:/// on the third try. This path must be manually...
4
3337
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 to change. here are some tests I did to see what was wrong: $blah = opendir("blocks"); while ($file = readdir($blah)) {
4
4216
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 Directory.GetCurrentDirectory() and combine it with my file, the XmlTextWriter couldn't open the file. The returned path from Directory.Get... contains only one \. Is this the problem?
3
11017
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 name and logon information. The problem which I understood from this is that the path is hardcoded in the crystal report and the database is in my bin folder. when I run my app on other machines it is looking for the database in that folder and...
9
1545
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" runat = "server" text = "<img id = 'img' src = 'Images/picture.gif' /text " />
1
2876
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'); background-position:center; background-repeat:no- repeat;" <!-- My footer content goes here. --</div> This Footer.ascx is under a folder called /UserControls (the leading forward slash indicates the root of the web application, same below).
1
2970
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 not displaying the page as it display when we visit the page directly in browser. Instead it references all the file path,
10
1955
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 resolve the issue by removing the ../ from the beginning of the include file path. But now I am looking at making this modification hundreds of times in all kinds of files. I'd like to keep the dev env similar to the live env so I can port changes...
0
9661
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10582
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7778
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.