Chetan Chetan - 2 years ago 71
PHP Question

how to fix this error in Drupal Site?

I have Drupal 6 Site.

Here are my Urls:-



In my page.tpl.php, in the header

<link rel="stylesheet" type="text/css" href="<?php echo path_to_theme(); ?>/css/bootstrap/css/bootstrap.min.css" />

Now if I enter the url, stylesheet is picked and rendered with no issue.

But in case I enter the url as at the end) or any inner pages say, stylesheet is missing

If I inspect the page and manually put a / in the stylesheet path, it is again rendered.

Its not just the issue with stylesheet but with scripts + images as well.

I do get sometimes warning message in chrome as

Resource interpreted as Stylesheet but transferred with MIME type

What should I do to fix it?

I am using Drupal v6.0

Answer Source

Take Note: Drupal 6 is no longer officially supported by the community. While there are some places that are offering long term support for Drupal 6, you should plan to move to Drupal 7 or 8 soon.

You appear to have two issues: the path to your CSS file and the headers sent by the web server for CSS files. The main issue you mentioned is the CSS path, so most of the information here pertains to that.

path_to_theme() provides a reference that is relative to Drupal root, which is usually the site root (/) but could be something else if Drupal is running in a sub directory or some other configuration. You need to prepend the result of base_path() if you are going to hard code the link.

You are nearly always better off using drupal_add_css() from within a hook in your module or template.php instead of hard-coding the link in a tpl.php file. Drupal_add_css() allows Drupal to process your CSS through its built-in aggregation. The hook_preprocess_HOOK() functions are common places to add CSS and JS files.

The MIME type notice is likely caused by the web server not detecting CSS files correctly and setting the right headers. The fix for that depends on both your web server selection and hosting environment (Google should help you find the issue and fix it).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download