Tommo
Tommo

Reputation: 1125

Moves website to subdirectory - Getting images/css paths to work?

Ive got a website in a subdirectory but all the image, link and CSS paths are set like this:

"/images/error.png" or "/help.html" or "/css/styles/stylesheet.css"

I've tried a million different .htaccess things and tried setting the base href tag to the domain.com/subfolder.

I can't seem to get anything to work!

Also: There are hundreds of files in this system so I can't manually go and change all the paths to relative.

Upvotes: 2

Views: 1093

Answers (2)

anubhava
anubhava

Reputation: 785481

When you wrote: Ive got a website in a subdirectory I am assuming that you moved all images, css etc to subdirectory as well.

If that is so you can manage it using a simple RewriteRule. Create a .htaccess under DOCUMENT_ROOT with this code:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# if this is a link
RewriteCond %{REQUEST_FILENAME} -l
# forward to subdirectory if it is not already subdirectory
RewriteRule ^((?!subdirectory/).*)$ subdirectory/$1 [L,NC]

Upvotes: 2

LiamB
LiamB

Reputation: 18586

Use Relative Paths (http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm)

So if your images are in

/SubFolder/Images/ 

and your viewing the file

/SubFolder/index.htm

Images/fileName.png

Will work.

Upvotes: 0

Related Questions