I have a codeigniter application that is working perfectly on my hostgator hosted domain.
I have configured .htaccess and config.php to remove the index.php from the URL. As mentioned this is working 100%. I now need to move the application from my hostgator server to a local server in South Africa with Afrihost.
the modified htaccess and config file are shown below:
my htaccess file is:
RewriteEngine on
RewriteBase /
# Prevent CI index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
# Prevent user access to the CI system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Prevent user access to the CI application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
and my config.php file is:
$config['base_url'] = 'http://logicoportal.co.za';
$config['index_page'] = '';
// let me know if you need to see any other setting
When I try to browse to the domain http://www.logicoportal.co.za I get error This page can't be displayed.
If I browse to my ion auth controller, http://logicoportal.co.za/auth/login I get 404 error The webpage cannot be found.
If I browse to my full codeigniter default path, http://logicoportal.co.za/index.php/auth/login I get error This page can't be displayed
I am assuming it is an htaccess configuration error however I am not sure how to correct this. read many an article with no luck. Alternatively is there another config setting in codeigniter to support this?
I have spoken to the new hosting company, Afrihost and they say they cannot help in this regard.
Any advice / direction would be appreciated.
Thanks as always.
Working Solution:
htaccess file to remove index.php on shared hosting server
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(index\.php|\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) ./index.php [L]
Try removing the ? in:
RewriteRule ^(.*)$ /index.php?/$1
So it's:
RewriteRule ^(.*)$ /index.php/$1
Related
I'm trying to make any image file name that doesn't exists in my server to load default.jpg in it.
This is what I tried on my .htaccess:
RewriteEngine On
RewriteRule ^\w+\.jpg$ /default.jpg
But everytime I access my /randomimagename.jpg the browser redirects me to my domain root.
Any ideas?
Try with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.jpg$ /default.jpg [NC,L]
I'm relatively new to Codeigniter and MVC. But, have successfully made two apps 'Locally'. While exploring, I found a way to remove 'Index.php' from the URL and also about custom routes. The .htaccess file that i have works like charm locally, but when trying to host it; there is a issue 505 internal server issue
Here is the first .htaccess code that i have (works locally) :-
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
When i use the code above there is an error. And, the app works only when .htaccess is removed. (I then have to use the inconvenient long URLs)
After a brief research and using different .htaccess without success, i asked one of my friends who has a Hosted CI app successfully running. He sends me a file which leads me the landing page without any problem; but, cant call any functions with/without using routing .i.e. If i use the custom routed URl (www.mySite.com/contact) then also it leads me to the landing page, the same with actual URL scheme (www.mySite.com/welcome/contact_page)
The new code here:-
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Using this code shows me the landing page but i cannot navigate any further from there. When i try to call a function the landing page reloads. This, I think is because of the last error Handling Code (ErrorDocument 404 /index.php)
Does anyone know what the solution the problem might be??
questions
Why doesnt the first .htaccess code work when hosted?
What may be the issue with the second available .htaccess file??
Do you guys have better .htaccess file? If yes, can you post it here??
Try this .htaccess (Codeigniter Recommended )
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
or
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In application/config/config.php
$config['base_url'] = 'http://stackoverflow.com/';
$config['index_page'] = ''; # Should be empty
And make sure Controller name, Model names are in proper way. Bcz Linux Host is an Case-Sensitive.
I have my own CMS built using CodeIgniter (actually, it's not me who developed it. My client gave it to me from their previous developer). No, I'm in the process of migrating the CMS to a new server. I set it up and everything works fine. Except, I can't access my phpmyadmin installation which reside on the subdirectory of my public_html (which contain the CodeIgniter CMS).
www.mysite.com <-- this to access my CodeIgniterCMS based website
www.mysite.com/phpmyadmin <-- this to access my phpmyadmin
installation, which currently inaccessible and just showing CI's
default 404 error page
This might have something to do with CodeIgniter routing configuration or htaccess file and stuff like that. But I'm a total newbie on both CodeIgniter and htaccess.
What should I do to make me able to access my phpmyadmin?
this is my codeigniter htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
let me know what other information (chunk of code, config files etc) should I show here to give better detail of my environment
Your htaccess is not poking a hole through to let access to phpmyadmin.
try
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(phpmyadmin|index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I have a cakePHP app working at http://domain1.com/domain2, and want to point http://domain2.com/ to this application.
I have done this change the document root of domain2 to public_html/domain2, but, when I go to: domain2.com all css, javascript and images are not loaded, with a message saying controller not found.
What I can do?
All domains have a folder with their domains without the TLD at domain1.com, I think if I create a htaccess and get the domain without TLD, and finally change rewriteBase, will work as expected, but don't know how to do this.
Current htaccess of domain2:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You can try adding an htaccess file in domain2's document root with the following rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(css|js|png|jpe?g|gif|bmp|ico)$ [NC]
RewriteRule ^/?domain2/(.*) /$1 [L,PT]
This should remove the domain2 part of the links.
This ones a new on me. I'm transferring a site I made in codeigniter to a godaddy shared hosting server. I can get to the home page with:
http://www.example.com
But when I try to go to the other pages like:
http://www.example.com/about-us/
It throws me this error message:
Not Found
The requested URL /example/index.php/about-us/ was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
If I use:
http://www.example.com/index.php/about-us/
The page appears as clear as day.
I have looked up CI workaround , but my site is more of static pages then dynamic pages.
Overall, my question is, what am I doing wrong and does this have anything to do with having a godaddy shared hosting account?
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
CI Config file
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
CI autoload file
$autoload['helper'] = array('url');
09-30-2011 Update:
In the .htaccess use:
# Options
Options -Multiviews
Options +FollowSymLinks
#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /
#Removes access to CodeIgniter 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]
#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
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
In the CI config file:
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
Source: codeigniter.com/wiki/Godaddy_Installaton_Tips
It's an .htaccess issue. Try changing your .htaccess file to:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Your updated .htaccess is right. you need a small change in it.
change below line in your .htaccess file:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and in your config.php
$config['uri_protocol'] = 'QUERY_STRING';
This is not a godaddy solution, but same error on my WAMP localhost...
I had a simple fix to this, which started to occur after I upgraded my WAMPserver. It had set up a new apache config and it had turned off the rewrite_module.
To fix, I just left click wamperver icon->Apache->Apache Modules->rewrite_module and make sure that is ticked.