I have codeigniter running fine on my local machine but when I push to the server the routing falls apart. For my set up codeigniter runs from a sub directory named 'secure', so this is the .htaccess file I have created in the 'secure' directory:
RewriteEngine on
RewriteBase /secure/
RewriteRule ^assets/less/icons/(.*)$ /secure/assets/icons/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
The routes file currently looks like this:
$route['logout'] = "secure/logout";
$route['passwordReset'] = "secure/PasswordReset";
$route['default_controller'] = 'secure';
On my local set up if you were to go to the URL '/secure/dashboard' controller 'Dashboard.php' is correctly called and index initiated. However if I go to the same URL on the server it is trying to call the controller 'Secure.php' instead of 'Dashboard.php'.
I'm not sure what is different between my local environment and the server thats stopping the server ignoring the 'secure' part of the URL, I thought that this line in the .htaccess file should sort out the sub directory: 'RewriteBase /secure/'.
Any feedback is very welcome right now :/
I finally got to the bottom of the issue. My server holds a few different environments for development which do not run directly from the http root directory. This was causing the variable $_SERVER['SCRIPT_NAME'] to equal '/staging/secure/index.php' instead of '/secure/index.php';, so I simply added the following to the top of the index.php file
$_SERVER['SCRIPT_NAME'] = '/secure/index.php';
Related
I have requests coming to my server already. I want to v2 out my API calls.
Currently I have the directory /v2/ and within that I have index.php
If I call /v2/index.php?path=users/123 I get the right data back from my database. All is well.
But to standardize my code, I want to redirect /v2/users/123 to /v2/index.php?path=users/123
I have mod_rewrite loaded in Apache, tested with phpinfo(). I am not sure whether I need to place my .htaccess within the v2 directory or at root. I do not have any .htaccess in root today, and I do not want to modify any calls not made to /v2/.
Any pointers where to place the .htaccess file and the right conditions to do so?
My current file is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /v2/index.php?path=$1 [NC,L,QSA]
I have put it in the /v2/.htaccess directory, but navigating ahead of /v2 yields 404 errors.
Thanks!
I copied a fully functional CodeIgniter app into a new server, updated the config.php base url, and setup all database parameters accordingly.
An interesting problem I'm having is that the new install (in new server) returns a 404 for all controllers I try to access. However, when navigating to the base URL, my default controller welcome.php defined in routes.php is rendered fine on the browser.
$route['default_controller'] = "welcome";
This suggests to me that CI is running OK but there may be some other routing issue I'm not figuring out.
My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
which works fine on the other server.
Any ideas what I'm doing wrong here?
Is your apache directory configuration set to AllowOverride All?
I am working on my own PHP Framework. I am currently developing it on localhost and everything related to project is in subfolder called RuddyPhpFramework, so the path look like this:
localhost/RuddyPhpFramework/
In that folder, I do have index.php, the init point of whole Framework. I am currently working on my own router, but I have a two problems. First, in Apache's htaccess file a have this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) RuddyPhpFramework/index.php [L]
So whenever someone acces a page like this:
localhost/RuddyPhpFramework/something/smtelse/
The index.php will init the application and echo a path for me, which is:
[path] => /RuddyPhpFramework/something/smtelse/
But that is not excatly what I want. What I want is to get a relative path to subfolder (I don't know if I am explaining this correctly), for example:
[path] => /something/smtelse/
And another problem is that I want to setup the htacces so the last line would look something like this:
RewriteRule (.*) index.php [L]
So it will go for the index.php in the folder where is the htaccess file (/RuddyPhpFramework/index.php) and not /index.php, without specifying the foler, because if someone else will be using the framework, he might have it in a folder with different name.
first please stop we have enouth frameworks already. Now regarding your question. Your project is in localhost/RuddyPhpFramework so htaccess read url from first / so he skips localhost because it's domain and taiks uri witch starts from /
so you project setup is incorrect. what you could try not shure 100%:
RewriteEngine On
RewriteBase /RuddyPhpFramework/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]
please try it. and say did it helped.
I've just transferred a project of mine to the web and I have a file called "circlecrop.php" that's located in the root directory of where all the CodeIgniter files are. This php script basicall just makes any image with circlecrop.php?path=img cropped to a circle, very simple and it works fine locally.
This works perfectly fine locally.
I'm getting the following error:
Failed to load resource: the server responded with a status of 403 (Forbidden)
I can't access circlecrop.php directly even though I've got it set to 777, I haven't anything set within my routes in CodeIgniter I'm not sure it's needed?
Complete htaccess file
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|circlecrop\.php|images|js|profile_pictures|fonts|stylesheets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I've done some searching and can't seem to find anything, my only thought is that I need a way to directly access circlecrop.php and it will work. Any help is greatly appreciated!
Edit: I've updated the url that has the errors, maybe that's more helpful.
You need to include if your website placed on root directory
RewriteBase /
If it place in test folder for example use this.
RewriteBase /test/
simply use site_url() on every link and action instead of base_url().
This worked for me:
I replace .htaccess content by the following:
RewriteEngine on
RewriteCond $1 !^(index.php|application/themes|application/theme_path|images|assets|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Update your base_url according to your live host in config.php
$config['base_url'] = 'SET YOUR SITE URL HERE';
config.php is located in /application/config
I suspect this may be a webserver configuration change that has taken place, and my hosting provider hasn't told anyone, but anyway...
I have a Codeigniter instance set up with the following directory structure:
/root
/codeigniter
/app
/sys
/www
/sandbox
/ci
/js
/css
/img
.htaccess
index.php
Therefore in index.php, I have the following variables:
$application_folder = '../../../codeigniter/app';
$system_path = '../../../codeigniter/sys';
These are relative definitions due to it being a shared hosting provider, however it does appear to be working that way so I don't think this is the issue (in WAMP i have those folder paths explicitly defined, e.g. c:/wamp/ci/application)
In config.php, I have the following variables set:
$config['base_url'] = 'http://******.co.uk/sandbox/ci/';
...
$config['index_page'] = '';
...
$config['uri_protocol'] = 'AUTO';
and my .htaccess file in www/sandbox/ci is set like so:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Up until a few days ago, this all worked fine, however, I replaced a fair few files just before Christmas, and may have accidentally overwritten something without realising it. This setup works fine on my WAMP server, but fails on my live server If I attempt to access any function in any controller that isn't the one defined in routes.php.
My routes.php looks like this:
$route['default_controller'] = "home_controller";
$route['404_override'] = '';
home_controller appears fine, however if I attempt to do something like login (which is processed via a form POST to auth_controller/login), it fails with 404. I do not have any additional functions in home_controller.
I get nothing interesting from setting the logging threshold to 4, and ChromePHP just suggests that it cannot find a path to the controllers.
mod_rewrite seems to be working, because if I add anything plaintext to the .htaccess file, I get a server error 500, and furthermore the index.php rewrite is working. I also have rewrite_short_tags set to TRUE.
I have tried all of the uri_protocol types in the config.php, and none seem to make any difference, so I feel like if it is something i've done, i'm either missing something from routes.php, or something missing from my .htaccess.
Any thoughts would be appreciated. Like I said, this entire setup works on my WAMP server without issue.
I think the problem is in your htaccess. Try this htaccess for a moment..
<IfModule mod_rewrite.c>
RewriteEngine On
# Set the rewritebase to your CI installation folder
RewriteBase /sandbox/ci/
# Send everything to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I hope this helps you out.