0

I'm new to expression engine and I run into this aggravating problem EVERY time I install EE. Whenever I upload my templates, my URLS break almost everytime. The only way to fix it is to go in an manuelly tag every image IMAGE/CSS/JS URL with {base_site} and then ensure my folders are all on the base of the my site/sub-folder. Is there any other way to ensure my URLs won't break at upload other than what I just said? It's just so time-consuming to have to do it all manuelly? Once again, this is in a sub-direction (i.e. website.com/_development_sites/mysite).

See the below code for an example. Do I really have to insert the {base_url} for all my JS/CSS files and IMAGE tags and image links in order for them to work? Isn't there a faster work around so I don't have to spend so much time customizing my HTML template before uploading?

Any ideas?

`

<link rel="stylesheet" href="{base_url}css/overrides.css" type="text/css" />
<link rel="stylesheet" href="{base_url}css/responsive.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />`
2
  • Can you clarify with some before/after code. Your question isn't overly clear. – stuartmcd69 Nov 26 '16 at 2:22
  • I added more code to be clear, sorry for the lack of example. – Greg Nov 28 '16 at 13:55
1

I'm not sure if this answers your question but I'll at least give a suggestions moving forward (it is probably too long for a comment). One reason I'm not sure if it answers your questions is because your .htaccess rules could handle this, but I wouldn't recommend that route.

If you install EE in a sub-directory (say http://www.site.com/ee-site/), you should be setting your site Default Base URL to http://www.site.com/ee-site/. Then, when you generate new templates, always use the {site_url} tag in the beginning of your links:

<link rel="stylesheet" href="{site_url}css/overrides.css" type="text/css" />

This is a best (or at least better) practice. This way, say you have three copies of a website that look like this:

Development site : Default Base URL : http://www.site.com/development/
Staging site     : Default Base URL : http://www.site.com/staging/
Production site  : Default Base URL : http://www.site.com/

You can work on a template in your development site, and as long as you always use your {site_url} tag in the beginning of your href and src parameters, you can copy that template between sites freely and it will automatically work.

You could even change domain from say http://www.site.com to http://www.new-site.com and as long as you set each Default Base URL for each site correctly, you'll be all set.

3
  • Great, that helps alot. Why do you advise against using the .htaccess file for doing this same thing though? Wouldn't that be faster? – Greg Dec 23 '16 at 19:47
  • It adds a level of complexity that lives outside of the framework and lives more in the "DevOps" role domain (server provisioning and deployment). You'd have to have different versions of your .htaccess file for each site, and if you need to change one, you'd need to change three. This eliminates that with essentially a CMS environment setting you set once and leave alone. – jrothafer Dec 25 '16 at 1:54
  • Note that what I said isn't exactly true; you can manage environments and ENV variables in at your PHP server level so you wouldn't actually need three different .htaccess files... but again, now you're diving deeper outside of the CMS for something you can solve inside. – jrothafer Dec 25 '16 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.