CodeIgniter URL suffix .html automatically for all URL - php

I am new in CodeIgniter.
I setup CI in my localhost Eg. localhost/MyProjects/CodeIgniter/welcome/index
I can able to remove the index.php from the url & I also completed the .html suffix
So, I can able to visit localhost/MyProjects/CodeIgniter/welcome/index.html & Its working properly.
So I am using my a tag like this:
Register
But, I dont want to use the .html in my link manually.
have any solution to show my visitor .html suffix automatically Eg. localhost/MyProjects/CodeIgniter/welcome/index.html Or localhost/MyProjects/CodeIgniter/welcome/about.html Etc
Here is my htaccess http://pastebin.com/cXUFjvbp

Just edit url_suffix in config.php .....
$config['url_suffix'] = '.html';
Use site_url()
<!-- No need .html -->
Register
<!-- Register -->
Or anchor()
// No need .html
echo anchor('welcome/register', 'Register');
// Register
Note : Dont forget to load URL helper with $this->load->helper('url');.

Change your config.php file
$config['url_suffix'] = '.html';

Just redefine the base_url function or make a new one. Look at the source of base_url method
function _base_url($path = NULL) {
return base_url() . $path . '.html';
}

Related

how to remove codeigniter functions from base url when routing

I routed my controller function and suddenly the function name is added to base URL, how can I remove this?
$route['editblog/(:num)']='Code/editblog/$1';
Then all of the sudden edit blogs are added to base URL and my external files are showing an error.
<script src="assests/vendor/slick/slick.min.js">
It shows:
<script src="editblog/assests/vendor/slick/slick.min.js">
Please help me, help will be highly appreciated!
You need to verify 1 things:
application/config.php $config['base_url'] = 'application/path/'; like http://example.com/ or http://localhost/applicationName/
Now you should use urls like
base_url('assets/js/filename/js');
base_url('controller/action/parameters');
In this way, it will generate correct urls.
You should change your URL's to:
<script src="<?php echo base_url('assests/vendor/slick/slick.min.js'); ?>">
Actually base_url is set in your applications/config.php file. -> config['base_url']. It MUST include trailing slash
in your config file:
$config['base_url'] = 'http://test.com';
when you call out the base_url(). You can use this :
<script src="<?= base_url().'/assests/vendor/slick/slick.min.js'; ?>">

Why is this link not generated correctly in codeigniter?

I'm using codeigniter and the link to my categories don't work right. Maybe I don't understand some settings of the framework. I have in my configuration file set this base url:
$config['base_url'] = 'http://hms.loc';
But when I click the "Home" category or any other category the link looks like:
http://localhost/hms/
But it should be:
http://hms.loc
When I click the "Rooms" category it is:
http://localhost/hms/rooms
How do I set this up correctly? And where can I specify such settings?
You can use base_url() or site_url() method from URL_Helper.
Please check the documentation:
https://www.codeigniter.com/user_guide/helpers/url_helper.html
I use xampp, my web app folder name is "s_v", so i using
$config['base_url'] = 'http://localhost/s_v/';
If your project folder name is hms , define base_url as
$config['base_url'] = 'http://localhost/hms/';
Other wise check in html contain
<base href="http://localhost/hms/">

How to add index.php in base_url() in codeigniter

In general when we use site_url() in anchor tag in php code it auto insert "index.php" before the controller like
/index.php/controllerName/methodName
But in base_url it doesn't insert "index.php".
I want to add auto index.php before the controller how site_url() works.
Already I searched and understood that the change will be in config file.
But want to know the specific answer what I need to change.
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.
Passing arguments to base_url() or site_url() will result in the following
$config['index_page'] = "index.php";:
echo base_url('assets/stylesheet.css'); // http://somesite.com/somedir/assets/stylesheet.css
echo site_url('mycontroller/mymethod'); // http://somesite.com/somedir/index.php/mycontroller/mymethod

How can auto add .html in last url with Codeigniter

i'm using Codeigniter for my website. I had add url_suffix in config
$config['url_suffix'] = '.html';
Normal i create $href with same below code
echo "<li>Products</li>";
I must add .html in last. How can i auto add .html in url but i don't need fill it in last
You should use site_url()
Your href should look like this site_url('controller/method');
You should use site_url() function for auto generate of URL in codeigniter
Use this:
echo "<li>Products</li>";
Instead:
echo "<li>Products</li>";

Codeigniter URL Overlapping. Not working properly

this is my code below.
<li>Why share?</li><li>
But after I apply this i manage to redirect to the page but when i try to press another page the url will be keep adding like this and cause page not found.
The page look like this
But when i try to link to home page, the url won't change back to /home only
Any solution? or another way to link the page?
Need help on this!
Thanks!
Your href should have a slash in front of it so that it goes to "root".
<li>Why share?</li><li>
If not, the browser will think it is relative to the current route. Or use Codeigniter's built-in site_url() function
<li>Why share?</li>
Read about relative/absolute here: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
You need to set your base_url() in config.php, and call the url_helper so that you can then use it.
Step by Step Instructions:
in application/config/config.php, set your base_url, I prefer to use something like this:
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
in application/config/autoload.php, add url helper:
$autoload['helper'] = array('url');
Use it in your views like this:
<a href="<?= base_url('about/why') ?>" > link </a>
Read this: https://www.codeigniter.com/user_guide/helpers/url_helper.html

Categories