0

I want to remove /public/index.php from my Codeigniter and Bonfire project URLs..

My current URL: http://localhost/public/index.php/page Desired URL: http://localhost/page

but I want the paths for link and images and robots intact! How does one do that? Any good resources for working with .htaccess?

LazyPeon
  • 339
  • 1
  • 19

4 Answers4

1

Try reading CodeIgniter URLs, subsection 'Removing the index.php file':

in the .htaccess

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

in the config.php :

$config['index_page'] = '';
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41
RichardBernards
  • 3,146
  • 1
  • 22
  • 30
1

can you try this?

RewriteEngine On

RewriteBase /



#Removes access to the system folder by users.

#Additionally this will allow you to create a System.php controller,

#previously this would not have been possible.

#'system' can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ /index.php/$1 [L]



#Checks to see if the user is attempting to access a valid file,

#such as an image or css document, if this isn't true it sends the

#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]

this works fine on my end

  • I get the screen "Welcome to Bonfire v0.7-dev" and I can continue from there but then everything is the same – LazyPeon Aug 14 '14 at 10:34
  • have you read codeigniter topic regarding this? https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html – user07192010 Aug 14 '14 at 10:38
  • or try this: http://stackoverflow.com/questions/1445385/how-to-remove-index-php-in-codeigniters-path/7930935#7930935 – user07192010 Aug 14 '14 at 10:39
1

I think you have to take following steps:

  1. Shift your .htaccess file from application to root directory

  2. Remove/comment old code (using #) in old file and paste below code

RewriteEngine on #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L]

  1. Remove index.php from config file against $config['index_page'] like below $config['index_page'] = '';

  2. Then activate rewrite module from Apache

It should work for you.

cursorrux
  • 1,382
  • 4
  • 9
  • 20
Rahul Joshi
  • 193
  • 4
  • hmmm this works fine but now I have to change every link on all my pages and exclude `public/index.php` any way around this? – LazyPeon Aug 14 '14 at 10:35
  • Well, I don't know how many links do you have to change, I think you will have to change them. But for future, you can store critical links in constant.php under config directory as a constant and can use the constant in each source file. – Rahul Joshi Aug 14 '14 at 10:39
  • just one more thing do you mind explaining what is that last RewriteRule? Something about ajax, I found that everything works fine without it – LazyPeon Aug 14 '14 at 10:46
  • Well, my apology but I don't know much about .htaccess language, but I change the code according to below link. This might help you http://stackoverflow.com/questions/8664480/in-apache-how-to-rewrite-name-to-ajax-name-php – Rahul Joshi Aug 14 '14 at 10:55
0

You copy the .htaccess file from application i thought into your basedir.

Or add a new .htaccess to your basedir.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Webice
  • 592
  • 4
  • 15