CodeIgniter Forums
htaccess issues - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: htaccess issues (/thread-36832.html)



htaccess issues - El Forum - 12-15-2010

[eluser]jordanarseno[/eluser]
Hey everyone,

I'm working on removing the 'index.php' from my URLs.
It's only half working right now - hopefully somebody can help!

First off, my project is called machinev2 - and here's my file structure...
I've moved the codeigniter_system and project application folder outside of the server root for security purposes:

WAMP
codeigniter_system
machinev2_application
www
machinev2
(other projects)

This structure allows me to keep the same codeigniter system folder for all projects
I've modified my main index.php file inside of the machinev2 directory to point to the codeigniter_system and machinev2_application directories (which of course, include the CI core, and all of my m's v's and c's!)

I followed the instructions listed here: http://codeigniter.com/wiki/mod_rewrite/ for a mod_rewrite - and I've placed the .htaccess file inside of the machinev2 folder.

It works - but it only works on my home page.

When users are not logged into machinev2 web portal, they are redirected to a login controller. Thus, with htaccess they are sent to localhost/machinev2/login.

All is good.

Now, when I click other links - for example, I have a forgot your password link that is linked to a 'forgot' controller.

When I click this, and other links - my URL craps out with index.php in it again:
localhost/machinev2/index.php/forgot.

How can I make the changes propagate across all controllers?

Thanks and Cheers,

JoAr


htaccess issues - El Forum - 12-16-2010

[eluser]Daniel Moore[/eluser]
Take a look at the following tutorial page on this and see if it helps to solve your dilemma.
http://www.danielwmoore.com/remove_index_from_codeigniter


htaccess issues - El Forum - 12-16-2010

[eluser]Gerep[/eluser]
Hi, this is my .htaccess file.

I work exactly like you and its working fine for me.

Take a look at the RewriteBase it was a damn problem to me a few days =)

Code:
<IfModule mod_rewrite.c>
    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]
    
    #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>
<IfModule mod_expires.c>
ExpiresActive On
AddType image/x-icon .ico
ExpiresByType image/png "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
ExpiresByType image/x-icon "access plus 30 days"
ExpiresByType text/css "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
</IfModule>
# gzip compression.
<IfModule mod_deflate.c>
  # html, xml, css, and js:
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript application/json
  # webfonts and svg:
  <FilesMatch ".(ttf|otf|eot|svg)$" >
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>


Hope it helps.


htaccess issues - El Forum - 12-16-2010

[eluser]Rob @ iFetch[/eluser]
[quote author="thelctrclengnr" date="1292491932"]Now, when I click other links - for example, I have a forgot your password link that is linked to a 'forgot' controller.

When I click this, and other links - my URL craps out with index.php in it again:
localhost/machinev2/index.php/forgot.

How can I make the changes propagate across all controllers?

Thanks and Cheers,

JoAr[/quote]
Is CI generating these links for you (i.e. are you using the base_url or site_url functions?

If so, have you correctly set `$config['index_page'] = "";`?


htaccess issues - El Forum - 12-20-2010

[eluser]jordanarseno[/eluser]
Thanks everyone - I was able to get things working through Gerep's code.
Your code initially posed identical problems as the original CodeIgniter wiki suggestion.

I found many static references to 'index.php' in my code - I've removed them and it works great.

Thanks all!

Cheers and Happy Holidays

JoAr