Getting default (not CI) 404 for all pages - codeigniter

I am trying to develop using CI for the first time. I have not changed any defaults WRT paths, .htaccess, etc. Two hours ago I was able to load pages; now I am not. All of this is on a virtual box running on my Mac, and I had been messing with the virtualbox settings in order to try to get the web pages to load while connected to a VPN (did not succeed). At no time did I edit any files on the VM, whether for connect settings or related to CI and my project.
Giving up with the VPN, I returned to my project to continue with code enhancements. Only now, as my title suggests, nothing will load. The default "It works" page loads so I know nginx is responding to requests. I don't get the Code Igniter 404 page -- I get the generic:
Not Found
The requested URL /index.php/c_login/ was not found on this server.
In this example, c_login extends CI_Controller and displays a view in its index function.
Based on my searches:
My config.php contains $config['uri_protocol'] = 'REQUEST_URI';
There was no .htaccess file previously, and that is still the case
I don't understand the bit about capital first letter in my controllers, as I've had lower case since I started the project and had no problem
Except for a minor change to a view file (not trying to load that one right now), nothing has changed since the last pull from the git server
I had left the welcome_message view and welcome controller in place when starting this project, and that no longer works either. Any ideas? I am at a complete loss.

Change this
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
then in .htaccess(this should be place out side of application folder)
RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Related

Migrating a CodeIgniter site to a different domain and moving the whole thing down one level in directory

I am working on a site, which is built with CodeIgniter.
I have never used the framework before...I've learnt a little bit in the last couple days but really cannot solve my problem.
I have downloaded the site and I want to upload it to my own domain so not to make changes to the live site before testing.
the original site is example.com.
I want to upload it to mysites.com/examplesite (this will be the base - I use this domain for all my clients' test sites).
I have moved all the files and the database is in place.
I have found the database configuration file and have successfully edited it.
I am having trouble getting the site to work, I think it must be because of the site now being down a directory level.
I have edited $config['base_url'] so that it is correct...I am pretty sure it is correct because I can now reach the homepage where I couldn't before editing that variable. But, i can only reach the homepage - when I click on a link to another page, I get 500 error Internal server error.
Does anyone have a quick fix for me?
Thanks!
Keep this code on your project's root .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /examplesite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Joomla not finding index.php after

I had turned Use URL rewriting to ON
Added some code in to the ht access file and this never worked.
I then turned off url rewriting and removed the code and now when I try to go to the website I am getting a 404 error.
I can still access /administration
the website is www2.daxtra.com
the page it should find is http://www2.daxtra.com/index.php/home
Does anyone have any ideas what has happened?
This was the code I added:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Thanks
Right, I've done a small test.
To get what you want, you need to following:
htaccess.txt (you don't need a .htaccess file)
Search Engine Friendly URLs set to On
Use URL rewriting set to Off
You finally need to ensure that your Homepage menu items it set to a specific component such as an article or something else, not an Alias
This will ensure that you get example.com/index.php/home
Hope this helps

domain.com/username mod rewrite in codeigniter

I'm new to mode rewrite thing. Started off with codeigniter a couple of days back and trying to get a hand at it. I'm developing a website which needs domain.com/USERNAME for better SEO results. But I'm unable to figure out as to what mod rewrite I should write to achieve this. I already have removed the index.php entry in config and my base url is http://127.0.0.1/myproject/. (I'm using XAMPP)
So I have to search for username in this format
http://127.0.0.1/myproject/USERNAME
and return the corresponding page. My current mod rewrite file goes as follows :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Any suggestions?
Thank you for your help :-)
http://daparky.com/codeigniter-vanity-username-personalised-urls/
this should solve your problem.

code igniter & mod_rewrite - one rewrite rule breaking another

I have a site built in codeigniter. We use short urls from our database & rewrite rules to redirect them to their full path.
For example,
RewriteRule ^secure-form$ form/contract/secure-form [L]
This works fine by itself. But I would like to use SSL on certain pages. I have edited the code so that if you go to one of these pages, all instances of http:// within the page are replaced with https:// but I need to rewrite the url to use it as well.
The pages all use the same template and all the content comes from the database so I can't just specify ssl on a particular directory.
The url's for the secure pages all start with 'secure' so I wrote the following rules and placed them above the other rewrites.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/secure/?.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/secure/?.*$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^secure-form$ form/contract/secure-form [L]
RewriteRule ^secure-different-form$ form/contract/secure-different-form [L]
all other rewrite rules for specific pages follow
then the default rewrite further down...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The problem is that when I add the rules to change the protocol, it ends up displaying 'form/contract/secure-form' in the url instead of 'secure-form'.
This renders the actual form on the page broken since it uses that url to build itself.
If I take out the rules that change the protocol, it displays secure-form in the url as it should, but the page is not secure.
What am I doing wrong?
----UPDATE----
Ooh, after over 20 hrs of searching, I think I finally have an answer. So, first time through, https is off & gets turned on. Then, because of the 301, it's run again & the page gets sent to form/contract/secure... But this time, https is on. Since the uri no longer STARTS with secure, it turns https off.
Hopefully, this will help someone else.

Insert Yii module string in URL using mod_rewrite for mobile browser

I want to rewrite URL to access Yii module when a mobile browser detected. In Yii, I make a new module called mobile. I don't use theming (which is the common method for mobile site) since I intent to implement quite different logics for normal browser and mobile browser user.
The mobile module will be accessed using http://localhost/project/mobile (or http://project/mobile in production).
The default .htaccess file for Yii is below
RewriteEngine on
RewriteBase /project/
#RewriteBase / #for production
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
The problem is I want to insert string mobile for every URL accessed by mobile browser.
for example
http://localhost/project/user -> http://localhost/project/mobile/user
http://localhost/project/login -> http://localhost/project/mobile/login
http://localhost/project/books/1 -> http://localhost/project/mobile/books/1
or for production.
http://project/user -> http://project/mobile/user
http://project/login -> http://project/mobile/login
http://project/books/1 -> http://project/mobile/books/1
Anyone knows what the new .htaccess for this will be?
I don't mind changing few variables for development and production server and for the mobile browser detection I guess I can use the rule from http://detectmobilebrowsers.com
Try this one
RewriteEngine On
RewriteBase /project/
# Redirect /project/*/ to /project/mobile/*/
RewriteCond %{REQUEST_URI} !^/project/mobile/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera|mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /project/mobile/$1 [L,R]
# Forward request to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
It was adapted from .htaccess showed in here http://ohryan.ca/blog/2011/01/21/modern-mobile-redirect-using-htaccess/
The easiest thing you can do here is group all mobile functionality under a "mobile" module, and use Yii's PreRouter functionality to redirect the user in Yii itself. This gives you a lot more control about everything.
class PreRouter
{
public function routeRequest($oEvent)
{
$oApp = $oEvent->sender;
if (<isMobile>)
$oApp->defaultModule = 'mobile';
}
}
In your config you add:
'onbeginRequest' => array('PreRouter', 'routeRequest'),
Under the main array (so NOT under modules, it's an app setting).
As said, this gives you a lot of control over everything. You can determine when the user is to be redirected (for example iPad is also a mobile but a lot of people want the regular site). With this method you can store for example in a cookie that they want to remain on normal site instead of mobile etc.
I know its not with rewrites as you requested but I still hope you find the answer usefull :)

Resources