Welcome Guest, Not a member yet? Register   Sign In
sample .htaccess code does not work as described
#1

[eluser]shark72[/eluser]
I'd like to remove the "index.php" from my URLs, so that controllers are called with mysite.com/controller, rather than mysite.com/index.php/controller. On this page:

http://ellislab.com/codeigniter/user-gui.../urls.html

These .htaccess contents are given as an example of one way to address it:

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

However, on my system, it breaks it further. Without this .htaccess file:

mysite.com and mysite.com/index.html are interchangeable
mysite.com/index.html/controller works as expected
mysite.com/controller generates a 404 (also as expected)

With the .htaccess file given in the example:

mysite.com and mysite.com/controller simply display "no input file specified"
mysite.com/index.php and mysite.com/index.php/controller load but with missing CSS (probably because my CSS directory is not excluded along with images and robots)

So I'm guessing that either the example .htaccess is a little buggy as presented, or there's something more fundamentally wrong with my site's setup. I'm guessing the latter.

Any ideas?
#2

[eluser]jzmwebdevelopement[/eluser]
Try:
Code:
# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|css|js|images|files|scripts|robots\.txt)
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
#3

[eluser]shark72[/eluser]
Thank you very much! That didn't entirely fix it, but made it a little better, so I know I'm on the right track. Now, "mysite.com/controller" displays "No input file specified" rather than a 404.

I'll hack on your version of the .htaccess, but if you or anybody else has any further insite, that would be great as well.
#4

[eluser]shark72[/eluser]
You got me in the right direction and searching the forum solved it. Changing this line:

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

To:

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

Solves it!

Apparently the latter is required for PHP5, although I don't see the relation between the PHP implementation and Apache's mod_rewrite engine.
#5

[eluser]InsiteFX[/eluser]
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymLinks
    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
    

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB