2

Suppose i have the following URL

subdomain.example.com/myfolder

where "myfolder" is the root folder of my CI installation (where the application folder is located).

I have the following .htaccess (Credits to Fabdrol & ElliotHaughin):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

When ever i try to access my website such as:

subdomain.example.com/myfolder/controller/etc...

It always returns a 5xx Internal Server error. However if i add

subdomain.example.com/myfolder/index.php/controller/etc...

It works perfectly. I am pretty sure there is something wrong with my .htaccess i just don't see where the problem is.

Could anyone please help me fix my htaccess? Thx

* FYI * I also tried to change the following line on my config.php

$config['index_page'] = ''; // Originally set to index.php
$config['uri_protocol'] = 'REQUEST_URI' // Originally set to AUTO

When i change the:

RewriteEngine On
RewriteBase /myfolder

It does not return 500 however, it does not display anything at all.

Just to give some information about the structure of myfolder

public_html
---|
   |
   |--mysubdomain_folder
   |     |
   |-----|--myfolder (my website where index.php, .htaccess and application folder are).
4
  • Look into this : CodeIgniter PHP Apache 500 Internal Server Error Commented Jul 31, 2013 at 10:41
  • @MadanSapkota i tried that but have no luck. The .htaccess configuration works perfectly on my other site (a non-subdomain site). Commented Jul 31, 2013 at 10:53
  • where is your httaccess file in web root or in CI root? Commented Jul 31, 2013 at 13:24
  • ci root, i put it together along side with index.php file, controller folder and other stuff. Commented Aug 1, 2013 at 1:12

3 Answers 3

1
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
Sign up to request clarification or add additional context in comments.

1 Comment

i am sorry mate but it doesn't work. I couldn't even go to subdomain.example.com/mywebsite (This throws an 5xx error).
0

I think i might have solved it using this configuration:

my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myfolder

#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,QSA]
</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>

My config.php file:

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

It turns out that since my application (my ci_root) is not in my root (public_html) i need to amend the RewriteBase from "/" to "/path_to_your_application"

And it turns out if you are creating a subdomain called "subdomain" it will create a folder inside your public_html named "subdomain" and you should treat this as the root of your subdomain. Hence i set my RewriteBase to "/myfolder" instead of "/my_subdomain_folder/myfolder".

I hope this solution could help others.

Thanks all for the helps and hints.

Comments

0

Just add a ? after index.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets)
RewriteRule ^(.*)$ index.php?/$1 [L]

I also recomend to let view the files but not the directories with:

Options -Indexes

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.