user3711642
user3711642

Reputation: 109

Fixing referencing "/" (root) for assets when site is moved to subdirectory

I have a site which is currently in public_html and throughout the code assets (images, css, js, etc) are referenced via /asset_folder/asset which due to the "/" at the beginning ensures the browser goes to root and works through the directories.

I need to move the whole site to a subdirectory and run another site in parallel in another subdirectory, so they will be public_html/website_one and public_html/website_two.

Is it possible to add a htaccess file or something to each site (subdirectory) that ensures that if a "/" root is referenced, it stays within the site's subfolder?

Kind regards Liam

Upvotes: 1

Views: 282

Answers (2)

dave
dave

Reputation: 64667

You could add

<base href="http://www.yoursite.com/website_one/">

in the head tag of any page on website one, and

<base href="http://www.yoursite.com/website_two/">

which will set the "root" of any relative path.

A possibly better option would be to turn each site into a subdomain, so insead of

http://www.yoursite.com/website_one/

you would have

http://www.website_one.yoursite.com

and then all the links would work correctly.

Upvotes: 1

Juan
Juan

Reputation: 118

Maybe using a relative path, I mean, don't put the "/" at the beginning of the url.

If you're using now:

  • /index.html
  • /images/image1.png
  • /html/section1.html
  • /scripts/jsfile.js

Change it to:

  • index.html
  • images/image1.png
  • html/section1.html
  • scripts/jsfile.js

Upvotes: 0

Related Questions