2

I am new to CI and don't know much about rewrite rules. I was able to find htaccess rules from stackoverflow post which allows me to remove index.php from the URL. The ht access rules are as following

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /siebeluigen/

 #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]

 #When your application folder isn't in the system folder
 #This snippet prevents user access to the application folder
 #Submitted by: Fabdrol
 #Rename 'application' to your applications folder name.
 RewriteCond %{REQUEST_URI} ^application.* 
 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]
</IfModule>

<IfModule !mod_rewrite.c>
 # If we don't have mod_rewrite installed, all 404's
 # can be sent to index.php, and everything works as normal.
 # Submitted by: ElliotHaughin

 ErrorDocument 404 /index.php
</IfModule>

But this doesn't work if I move my controllers to subfolder within the controller directly. for example

If I put my Application controller in following path

application/controllers/application.php

Then I can access it from URL

http://localhost/siebeluigen/application

But if my directory structure is

application/controllers/app/application.php

Then I get error with following url

http://localhost/siebeluigen/app/application

but it works like this

http://localhost/siebeluigen/index.php/app/application

So, I am pretty sure there is something in htaccess that I should be able to change to make it work.

Please help!!!

Update

My htaccess file was in the application folder instead of root. Moving the file to the folder were index.php is located solved the issue. I have marked the answer that is working. Thanks...

3
  • What error are you exactly getting when you go to http://localhost/siebeluigen/app/application? I tested your redirect code and it worked. Commented May 2, 2012 at 1:06
  • I get a webserver not found error "The requested URL /siebeluigen/app/application/ was not found on this server" Commented May 3, 2012 at 15:17
  • Well, I'm no expert mod_redirect myself, so I don't know what's wrong at the moment. Perhaps you could log how everything is being redirected and spot where it is going wrong (or post the results here). I read in another question you can log with: RewriteLog "/tmp/rewrite.log" RewriteLogLevel 9 Commented May 3, 2012 at 18:33

2 Answers 2

5

This is my htaccess file that I use on ALL my projects:

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # activate URL rewriting
    RewriteEngine on

    # do not rewrite links to the documentation, assets and public files
    RewriteCond $1 !^(images|assets|uploads|captcha)

    # do not rewrite for php files in the document root, robots.txt or the maintenance page
    RewriteCond $1 !^([^\..]+\.php|robots\.txt)

    # but rewrite everything else
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>

    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 index.php

</IfModule>  

Then - also make sure that inside your config.php file

  $config['index_page'] = '';

edit: you NEVER want to point someone to your application folder - you ALWAYS point them to your index.php - EVERYTHING goes through Index.php - and it does the re-routing to where it is needed.

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

3 Comments

I tried to use your htaccess file.. but it doesn't work either . I get a webserver "not found" error with this url localhost/siebeluigen/app/application and it only works with localhost/siebeluigen/index.php/app/application
firstly - are you sure you have mod_rewrite enabled on your local server? secondly - are you putting this htaccess file in the same folder as index.php (that is where it should be)
Thanks .. the problem was that my .htaccess file was in application folder instead of the index.php folder. Moving the file to the index.php folder solved the issue
2

This is the condition that is usually meant to redirect to application.php

RewriteCond %{REQUEST_URI} ^application.* 

app/application doesn't match this condition. Try changing it to this:

RewriteCond %{REQUEST_URI} ^app/application.* 

Comments

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.