Udaya Sri
Udaya Sri

Reputation: 2452

Codeigniter htaccess for localhost

I'm having some trouble with codeigniter routing. I have a live site in a hosting server & here is the htaccess of it.

#php_value memory_limit 256M
#php_value upload_max_filesize  50M
#php_value post_max_size  70M

AddType font/opentype .otf
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType application/font-woff .woff

AddDefaultCharset utf-8

<IfModule mod_rewrite.c>
   RewriteEngine on
   Options +FollowSymLinks
   RewriteBase /

   RewriteRule   ^favicon.* - [L]

   RewriteRule ^search /categories [R=301,L]
   RewriteRule ^login / [R=301,L]
   RewriteRule ^pages/disclaimer /pages/integritetspolicy [R=301,L]

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

   RewriteRule ^index.php$ http://%{HTTP_HOST} [R=301,L]

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

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1

   RewriteCond %{HTTPS} off
   RewriteCond %{REQUEST_URI} (utredningar/post)
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

   RewriteCond %{HTTPS} on
   RewriteCond %{REQUEST_URI} !(utredningar/post)
   RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]
 </IfModule>

 <IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
 </IfModule>

This works perfectly with the domain name (example.com ) & the hosting server. In the header.view & in other views links are given as

<href="/assets/styles/home.css?9">

But when I try to make this work in localhost in wamp , it doesn't work . Assets ( css / js / images ) are not loading & the url routing doesn't work.

I have modified these two lines

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

to

RewriteCond %{HTTP_HOST} !^localhost
RewriteRule (.*) http://localhost/example/$1 [R=301,L]

I changed the application/config/config.php , add the base url , remove the index.php etc ..

I have tried every possible way to make it work, please point out where am I doing the wrong .. Thanks a lot

Upvotes: 1

Views: 11223

Answers (3)

Lonare
Lonare

Reputation: 4683

I tried all solutions above but none worked for me so I tweeked things around and now my local server is working like a charm

here is what you need to do: As Saty says

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

Then add this htaccess code:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Upvotes: 0

Parag Tyagi
Parag Tyagi

Reputation: 8970

This is my .htaccess which works on both production and development server.

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

config.php

$config['base_url'] = '';
$config['index_page'] = '';

routes.php

# Default
$route['default_controller'] = "home";

Upvotes: 3

Saty
Saty

Reputation: 22532

1.Make below changes in application/config.php file

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2.Make .htacces file in your root directory using below code

RewriteEngine on
RewriteBase /codeigniter           // add this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Upvotes: 1

Related Questions