-1

My website project is based on MVC stratuctre so i have an url like [site]/admin/login or my url could be [site]/user/edit/[id] but in bootstrap we have css relative path like this:

<link href="libs/bootstrap/css/bootstrap.min.css" rel="stylesheet">

while my address is [site]/admin/login then [site]/admin/login/libs/bootstrap/css/bootstrap.min.css doesn't exists so i have to use absolute path to load css file likes:

...
<link href="http://example.com/libs/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://example.com/libs/jquery2.1.1/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="http://example.com/libs/bootstrap/js/bootstrap.min.js"></script>
...

but my problem is font's doesn't load when i use absolute css path for bootstrap.css you can see in this image when i use www. in url my page loads correctly and shows icon fonts: enter image description here

but when i open url without www. the font doesn't load and icon doesn't show: enter image description here

and i think it's because of css path without www is not equal font path with www . the url in image is real and you can test it yourself.is there any solution?

minttux
  • 435
  • 4
  • 8
  • 19
  • I actually don't get what you're asking. In fact, I don't even see a question here. – jbutler483 Dec 30 '14 at 11:07
  • have you tried loading the bootstrap file from the CDN instead your local directory, just for testing? http://www.bootstrapcdn.com/ – António Regadas Dec 30 '14 at 11:15
  • @jbutler483 could you read my total statements before put negative mark? i bold my question for you. so i suggest first read my question at end of statements then read my descriptions – minttux Dec 30 '14 at 11:25
  • I didn't d/v, actually? I would also like to add why you would you **want** to include absolute referencing? – jbutler483 Dec 30 '14 at 11:27
  • @António Regadas im not sure get your question but everything is load from host not local host and it's easy to test in your browser just open http://iiiwenews.com and https://iiiwenews.com and see different's – minttux Dec 30 '14 at 11:28
  • @jbutler483 as i mentioned before my project is mvc and it's not raw html file so site.com/admin/login is not on physical path there is no admin directory there is no login directory or whatever – minttux Dec 30 '14 at 11:30
  • Please see [this](http://stackoverflow.com/questions/317315/asp-net-mvc-relative-paths) - You could also drag your path onto your cshtml/html page and it will reference it automatically for you. – jbutler483 Dec 30 '14 at 11:32
  • @jbutler483 that MVC is different from mine it's asp.net and mine is codeigniter and php so if you get my problem and question then please remove your negative mark.the best solution is use redirect from `www.si...` to `http://site...` using mod_rewrite in htaccess and put all my resource on base `http://site...` – minttux Dec 30 '14 at 17:35

2 Answers2

0

Example you have a directories your_project/libs

if you have position in your_project/view/index.html

you need have in:

<link href="/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet">

you need add /libs to work, if is your case or other path

../sub-directorio = "/" add to go a up directory

Luis
  • 535
  • 2
  • 14
0

The easiest way to solve this problem if i want to use absolute reference is put all my path on http://example.com... base like:

...
<link href="http://example.com/libs/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<script src="http://example.com/libs/jquery2.1.1/jquery-2.1.1.min.js"></script>
<script src="http://example.com/libs/bootstrap/js/bootstrap.min.js"></script>
...

then use mode_rewrite to redirect http://www.example.com.. to none www http://example.com... in htaccess like:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

then if someone open a url with www it's redirect to url without www and page shows correct.this solution may be not best solution but it worked and solved my problem

minttux
  • 435
  • 4
  • 8
  • 19