Codeigniter 2 shared hosting sub-directory installation - .htaccess

I know this has been asked a lot of times before, but I did search a lot without finding an answer. So I'm hoping someone will help me out. I have a shared hosting and inside the public_html folder I wish to install my CI app. The sub-directory name is "hrms".
So I uploaded all the CI files to hrms. Now when I visit http://www.example.com/hrms/index.php/login/do_login I get the famous error No input file specified. I have tried with .htaccess file with several variations that I could find, but none have helped. The http://www.example.com/hrms/index.php is working, so I'm guessing all the config is all right.
What am I doing wrong? Also, is the .htaccess file a must, even if I intend to access the site via full URL?
==== .htaccess =====
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /hrms
#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 ^(.*)$ /hrms/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 ^(.*)$ /hrms/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 ^(.*)$ /hrms/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>

Much ado about nothing.
===== UPDATE =====
I've now discovered that the problem is with GoDaddy hosting (GoDaddy and CI have a hate-hate relationship, it seems). The trick is to define your index.php as index.php? (notice the question mark) in the config.php file.
Nevertheless, many thanks to everyone who put effort into it!
Please note: If you're fine with ugly URLs like http://www.example.com/index.php?/HomeController/myFunction and aren't using routing (like me for now), there is no need for the .htaccess file.

Related

having headache wtih codeigniter mod_rewrite ~!

I read lots of the mod_rewrite for codeigniter and lots of them were talking about creating a .htaccess file and inside the file with something like
I'm a beginner with codeigniter so I'm learning from youtube tutorials.
at first I only have apache 2.2 installed to run my php and after using codeigniter with mod_rewrite I realize it's easier to install wamp so I uninstalled apache, mysql then installed wamp which has everything.
After that I continued with the tutorial on youtube about mod_write. I activated the module in wamp.
Created this .htaccess file inside ci_intro which is the root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#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>
I went to the config/config.php and changed
$config['index_page'] = '';
things didn't work. I was getting the 404error then I was trying out few things in
RewriteBase /ci_intro/
and also even deleted the whole project and because I backed things up right before I try the mod_write. Even after I retrieved the backup. I still didn't get the error404 page.
I just keep on getting..
Since I'm using wamp, when I go to my localhost there's a section saying my project which is ci_intro...I click on it the image above comes out.
I put my mouse over to check what's the link showing when mouse over and the link shows
[CODE]http://localhost/ci_intro[CODE]
anyone know what's going on here?
That browser page you are getting, is a result of using a fake or unregistered domain-name... The browser is unable to resolve it to an IP address, so it "helps" you by reinterpreting your request as a search term.
This is happening because you are using "www.domain.tld" instead of "localhost" to access your website.
I'm not sure which WAMP distrubution you are using (there are many "WAMPs"), but your options are:
A) Edit the Windows Hosts file (C:\Windows\system32\drivers\etc\hosts) to locally resolve "www.domain.tld" to the local IP addres 127.0.0.1 (and make sure your VirtualHost or Server has that domain name as part of it's ServerName directive).
B) Use "localhost" instead... http://localhost/
C) Use a WAMP that automatically sets up website VirtualHosts for you and has a LocalDNS feature like Wamp-Developer Pro does - so none of the above matters.
Now once you get passed that, there might be some other issues... I'm guessing that .htaccess file should be in the DocumentRoot folder itself.

Cake php Sub Folder Installation, Temp folder errors from htaccess or file permissions?

My client has asked for a cake php app i've made for them to go into a sub directory on their existing server.
All works perfectly on my test remote and local installations.
Initially I had a problem with htaccess and had to add RewriteBase /quotesystem/ to my htaccess files in order to see the site at all. So I have changed my htaccess as below:
cake root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /quotesystem/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /quotesystem/app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
and webroot .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /quotesystem/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Now I can access my site but i get loads of warnings about the temp directory:
Warning (2): SplFileInfo::openFile(/web/sites/_p/_e/_t/petersen-stainless.co.uk/public/www/quotesystem/app/tmp/cache/persistent/cake_core_cake_en-gb) [function.SplFileInfo-openFile]: failed to open stream: No such file or directory [CORE/Cake/Cache/Engine/FileEngine.php, line 295]
You can see it here: http://www.petersen-stainless.co.uk/quotesystem
Now, i've CHMOD the temp directory to 777 so everyone should have permissions but i still get these errors.
I've deleted all of the files in these folders so that the temp directories have been cleaned.
When I use my ftp client - transmit - to look at the file permissions the owner appears as (?) and if i try to change it i get an error:
Could not change owner of “tmp”. Server said: 'SITE CHOWN' not understood
I dont get this with any other site I work on.
I don't understand enough to know what is going on, is this a permissions problem or an .htaccess problem or both? Or is it a server configuration problem?
If anyone can help shed some light on this and help my understanding i'd be very grateful.
UPDATE:
My directory structure on the server is as follows:
-- public
--- www
----- quotesystem
------- lib
------- app
--------- config
--------- webroot
In my experience, the SplFileInfo warning appears when Cake attempts to read/write cache that it does not have permission to access. Make sure your application has permission to read/write the cache/tmp folder (depending on your Cake version).
It's probably a .htaccess problem. The RewriteBase should be the same for both the webroot and app .htaccess. So the line in both files should be:
RewriteBase /quotesystem/
I personally never touch the .htaccess in the Cake root directory as it doesn't seem to be necessary to alter anything there.
In addition, /tmp/cache and it's subdirectories should be writable as well.

Htaccess rule to make urls like this ?page=1 look like /page/1 in Codeigniter

This is how my urls currently look:
http://mysite.com/?page=1
How can I make this work?:
http://mysite.com/page/1
There is a post on StackOverflow that asks the same question. But the accepted solution isn't working for me. Because I am using Codeigniter and my page results in a 404 perhaps because since the url pattern of a CI site is:
domain/controller/method
The system is assuming that I am requesting a controller called "page" and a method called "1" both of which of course doesn't exist. Or maybye it's due to a conflict with the other code in my htaccess file (which I downloaded from the CI wiki, it gets rid of index.php and does a few security things). Here is my entire htaccess file:
<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, '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. 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]
#Pretty urls for pagination links
RewriteRule (.*) index.php?page=$1
</IfModule>
The non indented bit is the solution I got from that other SO question that isn't working for me.
Any solutions to this CI pagination issue?
UPDATE
Ok, read some of the docs and now I have this working:
http://mysite.com/home/index/2
What would be the htaccess rule to turn that into?:
http://mysite.com/page/2
You should make this configuration at /application/config/routes.php (and let the .htaccess just for hide the index.php as you are already doing).
$route['page/(:any)'] = 'home/index/$1';
Or better, like #zaherg remembered (ensures that only numbers could by matched):
$route['page/(:num)'] = 'home/index/$1';
This way all the requests to http://mysite.com/page/2 will be treated internally as http://mysite.com/home/index/2 and so forth.
I suggest you take a look at CodeIgniter User Guide - URI Routing and CodeIgniter User Guide - Tutorial − Introduction.
Good luck.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
from CodeIgniter docs
That will handle removing the index.php, but what happens after that depends how CodeIgniter's query string handling is set up: it can be configured to use a query string rather than a path. See the link for more details.

htaccess query. 2 rewrites rules for 2 home pages

I'm hoping someone might be able to help with a problem I'm having due to my lack of experience and knowledge with htaccess.
What we're doing is running IP Boards forum software and wordpress both in the root directory. The IPB has the index.php file (because of having indexed url's) and the new Wordpress's index.php file has been renamed to blog.php.
At the very top of the htaccess file we've added: DirectoryIndex blog.php index.php - so the new wordpress opens first.
The problem I'm having is trying to have 2 rewriterules in the htaccess file for the friendly urls from the forum software and also the permalinks for the new wordpress.
I can only seem to have one or the other.
Please could anyone tell me, or point me in the right direction to get both working.
This is what I'm doing so far but sadly no joy, but works fine if we remove one of the condition and rewrites.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog.php [L]
</IfModule>
Many thanks in advance.
Not sure if you still want an answer. Either way, if you are trying to go to two different pages you need some way of distinguishing them.
DirectoryIndex basically tells the default file (and order) when entering a directory. So http://host.com/ with both blog.php and index.php in the directory will serve up blog.php because it is first in the list you gave the server. If there is only index.php, it will serve that. If neither (and you don't have anything else in the list) it will throw a 404 because no default file is found.
EDIT: it will try to list contents if not found. My bad. If you don't allow directory listing, then it will probably show an error code. To turn off directory listing look in options: http://httpd.apache.org/docs/current/mod/core.html#options
http://httpd.apache.org/docs/current/mod/mod_dir.html
Your rewrite rules seem to kind of want do the same thing in a different order. If you request http://host.com/a and a is not a file or directory (according to the conditions) it will go to index.php.. if index.php doesn't exist, then it will loop until the server catches it, because you don't check that. So, that means the second set of conditions don't do anything, because either index.php exists or it doesn't and the next set probably won't really be reached unless it does.
You need to decide how to differentiate the two (/blog/ for the blog.php and / for index.php or something) and make one of them the default. If you want to randomize it, I would suggest doing that through PHP.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
.. to redirect from root to /forums/ through htaccess try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule ^(.*)$ /forums/$1 [L]

RewriteCond to skip actual directories seems to be ignored

My problem is that The RewriteRule is still matching when I visit a physical directory, e.g. http://a-domain.com/foo/ where foo is a normal directory in the web root.
the .htaccess file has:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .? index.php [L]
It works fine on my dev server but not on a live WHM/CPanel server. I'm a bit lost.
I've tested this on my cpanel website and you're right and I found out where's the problem. when you try to access a folder in your website that doesn't have default file (index) , it tries to access the file that is responsible for 403 HTTP code, and because that doesn't exist, it rewrites URL to index.php.
All you have to do is add this to above of your .htaccess file:
ErrorDocument 403 /index.php?type=err&code=403
I tried this on a VM which mirrors my own shared service and it works fine for me. Have you got another .htaccess in the foo directory? If so, then the rewrite engine will ignore your one in DOCROOT and use this instead?
The /foo/ dir has basic authentication so it was failing when %{REQUEST_FILENAME} contained a non-existent file /home/the_user/public_html/401.shtml. I didn't think this was an issue because the basic authentication worked, and when I cancelled the auth prompt I was being served a standard 401 file. Usually when those ErrorDocument files are missing, Apache says Additionally, an error of type 404 was encountered while trying to use an ErrorDocument to handle the request.

Resources