1

I have a codeigniter website which has a broken link structure. The initial page loads normally. My Navbar looks like:

<a class="brand" href="#">myproject</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li class="active"><a href="#">Home</a></li>
              <li ><a href="http://localhost/projectname/basecontroller/Facts">Facts</a></li>
              <li ><a href="http://localhost/projectname/basecontroller/about">About</a></li>
              <li ><a href="http://localhost/projectname/basecontroller/contact">Contact</a></li>
              <!--<li ><a href="http://localhost/projectname/basecontroller/privacy">Privacy</a></li>-->
            </ul>
          </div><!--/.nav-collapse -->

I know this project worked correctly in the past . I believe it was deployed with a .htaccess file which is not present locally as I test it.

I've tested it with the following .htaccess file in the toot directory:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /projectname/index.php/$1 [L] 

This appears to fix the directory structure by turning:

http://localhost/projectname/basecontroller/contact

into:

http://localhost/projectname/index.php/basecontroller/contact

but now all the js/css does not appear to be applied to the page ( I'm using bootstrap ).

The head of my pages looks like:

<!DOCTYPE html>
<html lang="en"><head>
        <base href="http://localhost/projectname/">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title>my title </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">    

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">

How can I fix this?

2 Answers 2

3

I'd imagine that adding the css and js folders to the RewriteCond should do the trick (or whatever you named those directories):

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)

This excludes those paths from the rewrite rule posted below.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, That worked. Also I didn't realize that you can put folders in the RewriteCond
1

As sbeliv01 said, you'll probably want to add css and js folders to the RewriteCond, to exclude them from rewrites.

I also notice from the head section...

<link href="css/bootstrap-responsive.css" rel="stylesheet">

... you're loading CSS from a relative URL, so http://localhost/projectname/ will load CSS from http://localhost/projectname/css/bootstrap-responsive.css, while http://localhost/projectname/basecontroller/facts/ will load from http://localhost/projectname/basecontroller/facts/css/bootstrap-responsive.css. You probably want to change your head section as follows:

<link href="http://localhost/projectname/css/bootstrap-responsive.css" rel="stylesheet">

2 Comments

Thank you. I'm actually setting the base tag like in philsturgeon.co.uk/blog/2009/09/…. It makes deployment easier.
That's the best way for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.