Codeigniter .htaccess in godaddy

2019-03-02 10:26发布

问题:

I am struggling with this for hours now: I have a codeigniter application in a sub folder in a godaddy hosting, lets say:

mydomain.com/myfolder/myapp/

I have this .htaccess:

<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteBase /myfolder/myapp/

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

</IfModule>

I read this doc: https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips but it won't help neither. Maybe because my ci app is in a subfolder?

How can I hide the index.php? and make it work with friendly urls?

回答1:

Have your /myfolder/myapp/.htaccess like this:

<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteBase /myfolder/myapp/

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

</IfModule>

then in /myfolder/myapp/application/config/config.php you need to have this config:

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


回答2:

Use the following .htaccess for Godaddy hosting server. Please let us know if it works.

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


回答3:

Create a .htaccess file in you root directory (where codeigniter's index.php is) with this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    #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 %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

Then is your application/config/config.php :

$config['index_page'] = '';

This should solve the issue.

Hope this helps!



回答4:

I'm surprised nobody wrote that you're supposed to put

Options +FollowSymlinks

at the beginning of your .htaccess file, for a GoDaddy hosted website.