Codeigniter css error loading images - php

I've been messing around because when i look at the page it says that he cant load up the image but there are no errors in debugger so its probably a framework error or htacess. This happens after i create my view news witch i accept a param in url (the 4th).
my htacess
ReWriteEngine On
RewriteCond $1 !^(index\.php|resources|assets|robots\.txt)
ReWriteCond %{REQUEST_FILENAME} !-f
ReWriteCond %{REQUEST_FILENAME} !-d
ReWriteRule ^(.*)$ index.php/$1 [L]

Seems like its not getting the full URL.. Give the total image URL along with the domain name like
http://www.yourdomain.com/assets/images/uploads/uploads/b.pn‌​g

Try setting your base url example on config.php
$config['base_url'] = 'http://loaclhost/youyproject/';
Or If have domain some thing like
$config['base_url'] = 'http://www.example.com/';
Then autoload url helper config/autoload.php
$autoload['helper'] = array('url');
And then try using like
<img src="<?php echo base_url('assets/images/uploads/uploads/b.pn‌​g');?>" />
Make sure assets folder out side of application
application
assets
system
index.php

Related

loading controllers in codeigniter

For register page I have 'Register' controller
For login page, I have 'login' controller
I loaded url, form helpers
at the end of I have given login link as follows
Login
But it's showing the error.
Object not found!
The requested URL was not found on this server.
Change your htaccess file to this. I think it will work.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And Base URL should be absolute, including the protocol:
$config['base_url'] = "http://somesite.com/somedir/";
If using the URL helper, then base_url() will output the above string.
First Check Your base_url From application/Config/config.php file
Then Set Your base_url()
`$config['base_url'] = 'http://localhost/[your-project-name]';`
if your project have on root folder then set
`$config['base_url'] = 'http://localhost/';`
Note: In Login Controller May be You find index file. If not then must be set your function name. Like this:
Login/[your-function-name]
Login
Have you removed index.php from url using .htaccess file?
If yes the you can use <?php echo base_url('login'); ?>.
Or else you should use <?php echo site_url('login'); ?>.
$config['base_url'] = 'http://localhost/';
assuming your index.php is in htdocs directly and not some subfolder.
otherwise it should be $config['base_url'] = 'http://localhost/sub_folder/';
(trailing slash required)

CodeIgniter 3 : Rewriting URL with assets

I'm facing a problem with URL rewriting in CodeIgniter 3.
My files structure is :
site
-assets (.css and .js files)
-application (sites files : controller, ...)
-system (CI files)
-user_guide
To avoid index.php/ in URL, I put this configuration :
.htaccess
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
config.php
$config['index_page'] = '';
This way, my URL is not test.com/index.php/user/function but test.com/user/function.
Actually everything is working very well, but when some .js scripts try to call other scripts with relative URL, it calls wrong URLs.
For example, if one of my script wants to call assets/js/jsfile.js, I'm having a 404 error because it calls http://www.test.com/user/assets/js/jsfile.js, whereas it should be http://www.test.com/assets/js/jsfile.js.
To avoid this, I put <?php echo base_url() ?> in every <link> or <script> I call myself, but some .js libraries require intern callings, and I can not do this every time... I would like the real solution... Any idea ? Thanks a lot !
Change your htaccess file like this;
RewriteCond $1 !^(index.php|resources|robots.txt|assets)

Codeigniter base_url in plesk

Recently I uploaded a website which created using codeigniter framework into plesk. Inside the c-panal I changed the document root into httpdocs/public_html/cliftonhotel.ae, and I uploaded the files using FTP into the same. I changed the base_url into
$config['base_url'] = 'http://cliftonhotel.ae/';
The problem is if I enter the web address it loads fine(The home page), but the other menus are not working, they shows a 404 page not found error.
[http://cliftonhotel.ae/][1]
this is the site. What is the solution, thankyou.
Do some changes, hope it's work
// .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
// config.php
$config['index_page'] = ' ';
It seems that the links you have created are missing index.php
For example: http://cliftonhotel.ae/index.php/home/about works
but http://cliftonhotel.ae/home/about does not.
So you have to either change the links or edit your .htaccess for url rewriting

I can't show images in codeigniter project

I'm trying to display images that I upload to my FTP but I don't know what I'm doing wrong.
First of all, I'm saving "uploads/images/".$image['file_name'] in my DB to know the relative URL of the file.
Later, in the target view, I declared the helper('url') and helper('html') to use without any problem the next functions:
img()
base_url()
Having all this done, I call the image as img(base_url($object['image_url'])) where object['img_url'] is called from my DB with the correct structure.
I tried to use the <img> tag too, but the src doesn't loads correctly.
The url that I'm getting from the DB is the correct one, but if I load it at the browser, it appears a 404 error because there is no "uploads" class with "images" method. My uploads folder was created at root level of the project.
What I'm doing wrong? I had to change something in the configuration of the project?
CodeIgniter routes all requests to index.php and looks for a controller. Try adding this to .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Do you have .htaccess. Example:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|fonts|products_images|shops_images|uploads|assets|robots\.txt|migration)
RewriteRule ^(.*)$ /dobrioferti/index.php/$1 [L]

codeigniter url http://www.website.com/index.php/index.php/page

Ive been struggling to get a .htaccess file working on codeigniter, im having that issue when you load any other page aside index that, every time you click on a link in my nav bar it tacks on an index.php/, so after the first click on a link, you end up with things like http://www.website.com/index.php/index.php/page
When I open an image from site
http://website.com/new/index.php/website.com/new/img/gallery/fw1.jpg
My link same as
index.php/About">Aboutour team
My config file
$config['base_url'] = 'website.com/new/';
How can I solve this problem?
I use the following .htaccess file, which has always worked for me with CodeIgniter:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You should also check your application/config/config.php file to make sure it has the following lines (a blank base_url setting means CodeIgniter will auto-generate it):
$config['base_url'] = '';
$config['index_page'] = '';
You might also want to check you're generating the links themselves correctly. You can use site_url() for every link to ensure maximum portability. e.g.
<a href='<?=site_url('about')?>>About</a>

Categories