Reputation: 2993
I have a project which I wish to place in a sub-directory of a web root directory.
So if I had: /public_html as the web root directory
I want the project to live in: /public_html/myproject
Now, the project will eventually live in the root folder, so I want to make as few code changes as possible, but during testing it must stay in the sub-directory.
The issue is with the following:
<img src="/images/image1.png" alt="" />
This works fine when the project is in the document root, because the leading forward-slash is doing it's job.
However, when the project is in the sub-directory, the / takes the relative path back to the web root folder.
How can I alter .htaccess to prevent this? I need the leading forward slash to reference the "/myproject" folder instead.
Any ideas on how it can be done?
Upvotes: 0
Views: 776
Reputation: 399
If you have the apache module mod_rewrite enabled, you could add the following to your .htaccess file in the root folder.
RewriteEngine On
RewriteBase /
RewriteRule ^images(.*) /myproject/images/$1
You can find more information on this here:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Upvotes: 3