I try to use Codeigniter in localhost with WAMP.
Problem is, that I can open just basic function in basic controller, and when I tried to use root like site/controller/function, its do not work. Result is that it put me back to wamp start page, or text that page not found.
Mostly I found solutions about makingthe .htaccess file, and many variations what to put in it.
To uncomment rewrtie mod in wamp .conf file. And in my web page to leave index_page empty.
But It do not work for me.
My controller:
class Home extends CI_Controller {
function index() {
$this->load->view('index');
}
function slide() {
$this->load->view('slider');
}
}
And my web page is in: www/mysite/....
Try this .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?$1
RewriteRule ^(CSI) index.php?/CSI
AddType text/x-component .htc
EDIT
Add the above code here
Don't change any thing in CI system..
Once check this repo
Related
When I open the site with the server.php file, my index page is displayed (index.blade.php), and the link on that page to the list page (list.blade.php) opens successfully. I encountered issues with it recognising my javascript files when I access via server.php? However if I open the public folder it puts me at my index page and javascript files are recognised...
When I open the public folder, and I click the list link I get "Sorry, the page you are looking for could not be found."
web.php
Route::get('/', function () {return view('index');});
Route::get('list', 'IngredientsController#display');
IngredientsController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Ingredient;
class IngredientsController extends Controller
{
/* Displays list of ingredients in db */
public function display()
{
$ingredients = Ingredient::all();
return view('list', compact('ingredients'));
}
}
ingredient.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Ingredient extends Model
{
}
link on index page to list page: List url
htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Laravel doesn’t use the root for including the files. So yes your IDEA see your files includes correctly but laravel it doesn’t.
See this post answer:
https://stackoverflow.com/a/28915577/5334073
Laravel uses the public folder as the ‘root’ folder. That’s just how Laravel works. To call that root you should use the URL::assets function as explain the the answer from the post I gave you.
Above RewriteEngine On I put Options +FollowSymLinks and above RewriteRule ^ index.php [L] I added RewriteBase /nameoflaravelproject/public/
I added these two lines of code and it works. Sorry I dont really understand this so if someone can explain to provide a better resource for other users then thats great.
codeigniter page not found showing but working fine in local server.
I had uploaded codeigniter file of one basic simple page on live server but there it is showing no page found and same file it is working on local server.
In that I had
mine.php ---- controller
index.php --- view
I loaded in routes default controller - mine in config base url- domain.com removed index.php also
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
can I know please why it is showing page not found, might be some routing issue but I had loaded default controller also. Please help out on this
First of all start error logging properly so you can see the actuall error.
Change your file name's first letter capital. This is mendetory as explained here ci3 manual - controllers. It says class name as well as file name must start with capital. ( If your Dev machine is windows then it will not show errors if you don't follow this rule. Because window's file system is case insensitive. But on your server it is linux.so it will show error)
If you still don't get it working then try access the url with index.php in it. Temporaryly disable .htaccess .If you get it working then may be you have problem in . htaccess. Try the following link to properly remove index.php from your url. Expression engine forum .This htaccess worked for me on all different server I have used.
add this in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|asset|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I am using flashdata to store my search query so I can retrieve it when users navigate to the next page.
This is how I store the flashdata
$this->session->set_flashdata('searchQuery', $queryStr);
This is how I retrieve the flashdata.
$queryStr = $this->session->flashdata('searchQuery');
Flashdata is working fine locally but when I host it on my server, it does not work on Chrome(Windows) and Chrome(Android) but works on IE(Windows). Also it works perfectly fine on Chrome(iOS). I've also did a test case and it only works on IE(Windows) and Chrome(iOS). Anyone know what's wrong?
class Flashdata extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function index()
{
if ($var = $this->session->flashdata('test'))
{
echo "Found data: $var";
}
else
{
$this->session->set_flashdata('test', 'flash data test');
echo "Set data";
}
}
}
Here is my .htaccess file
# 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]
The problem is most likely caused by the last RewriteCond in your .htaccess
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
The above is used to list requests that shouldn't be routed to your applications index.php.
What is likely occurring is that your site includes a request for an icon/css/image/etc that you don't want routed to your application. As this request is passing through your application it is intercepting your flashdata (which is only available for the next request), which means it is becomes unavailable to your actual request for the page.
An example of this is often a favicon.ico, although there are other cases. I think Chrome will request a favicon even if one isn't specified in the <head>.
You could solve this by adding the favicon.ico to your list of excluded requests:
RewriteCond $1 !^(favicon\.ico|index\.php|images|robots\.txt|css)
It's possible that this is not caused by a favicon.ico, but another request for something completely different. The best way to get to the bottom of this is to log all your requests to a file and check what is happening at that point in the code.
I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.
<?php
class site extends CI_Controller
{
public function index()
{
echo "Hello World";
}
function dosomething()
{
echo "Do Something";
}
}
?>
When I try to access it using http://..../index.php/site I get the output ... "no input file specified" .... by the way, I named the file site.php
Just add the ? sign after index.php in the .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and it would work !
Godaddy hosting it seems fixed on .htaccess, myself it is working
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
I found the answer to this question here..... The problem was hosting server... I thank all who tried .... Hope this will help others
Godaddy Installation Tips
RewriteEngine, DirectoryIndex in .htaccess file of CodeIgniter apps
I just changed the .htaccess file contents and as shown in the following links answer. And tried refreshing the page (which didn't work, and couldn't find the request to my controller) it worked.
Then just because of my doubt I undone the changes I did to my .htaccess inside my public_html folder back to original .htaccess content. So it's now as follows (which is originally it was):
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
And now also it works.
Hint: Seems like before the Rewrite Rules haven't been clearly setup within the Server context.
My file structure is as follows:
/
|- gheapp
| |- application
| L- system
|
|- public_html
| |- .htaccess
| L- index.php
And in the index.php I have set up the following paths to the system and the application:
$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';
Note: by doing so, our application source code becomes hidden to the public at first.
Please, if you guys find anything wrong with my answer, comment and re-correct me!
Hope beginners would find this answer helpful.
Thanks!
My site is hosted on MochaHost, i had a tough time to setup the .htaccess file so that i can remove the index.php from my urls. However, after some googling, i combined the answer on this thread and other answers. My final working .htaccess file has the following contents:
<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|app_upload|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
One of my Codeigniter apps started returning this error after i restarted my server.
When I checked the Codeigniter error log it says something like:
"...[error] 879#0: *273 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/pathToWebsiteRootFolder/index.php) is not within the allowed path(s): ".
So I added this:
open_basedir= /pathToWebsiteRootFolder/index.php:
To a user.ini file I created in my website root folder.
And this Solved it.
FYI: Im using an NGINX web server.
However, Its strange because I didn't have to do this for the other Apps on the same server.
Hi all
I want to serve some static html pages in codeigniter context. I dont want to bypass the index.php file in the base_url.
But when I user the call to the HTML file, it dispays the 404 error page.
I appreciate any help for this topic from guys who already solving this problem . Thanks for all in advance
I want to precise this elements:
my real problem is to serve PDF file for users to display in the browser only an not to save the PDF file. So I convert the PDF to HTML Files. The output is a directory with HTML files linked betwen them and ther images/button, CSS, js for navigation
when i put this HTML-OUTPUT in ci\Docs\HTML1 directory I can access it whith this URL localhost/ci/docs/html1/index.htm.
But where i use localhost/ci/index.php/docs/html1/index.htm I get A 404 error page.
So I moved The HMLT1 directory to the Application\views directory. And i stil have the same error. My .htacces look like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Thanks Guys for your help
Create the static HTML file as a view and then just load the view:
$this->load->view('static.html');
You can then access this file as a normal controller. It all depends on how you have set up your .htaccess as well.
For me I just add a folder name for my static html pages into the .htaccess to exclude it from regexp like below, and it work. Just to exclude it from rewrite URL to index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|sitemap\.xml|static-html)
RewriteRule ^(.*)$ index.php/$1 [L]
$route['your-page-url'] = "/page/message/your-page-url";
In your Page controller function:
public function message($page = 'your-page-url')
{
$data['title']= 'Your Page Title';
$this->load->view('/header',$data);
$this->load->view('pages/your-page-url');
$this->load->view('/footer');
}