2

Hi i am using Codeigniter PHP framework.

Is there is any way to display .html extension rather than .php extension in URL?

6 Answers 6

2

Set your url suffix on your config.php found here

/application/config/config.php $config['url_suffix'] = '.html'; //@ line 60ish

Sign up to request clarification or add additional context in comments.

2 Comments

It works for regular page request. but what about ajax request. when we made request to controller using ajax it brokes. please suggest
what is the request url for the ajax?
1

I haven't actually tried it myself but see the section Adding a URL Suffix in this part of the user guide.

Comments

1

Just add following to Apache's config and it will process .html files with PHP:

AddType application/x-httpd-php .phtml 

With that you can rename your .php files to .html.

Or you can use mod_rewrite to handle this on the fly

Comments

0

use a .htaccess file that does a url rewrite .html to the equivalent .php

if you are using codeigniter you should even be thinking of hiding any extension altogether.

Comments

0

If ur using APache. You can use URL Rewrite Rule.

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Comments

0

As others said, creating a .htaccess file will allow you to rewrite .php to .html. The following code should do the trick:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]

I am interested as to why you actually want to do this though. Codeigniter, by default, uses a segment based approach which is friendly and does away with query strings and file extensions. Using another htaccess rule, you can remove index.php from the url to make them even cleaner:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

So your urls can look like this: example.com/home, example.com/about etc. This is much prettier than having a file extension in the url.

More information about codeigniter URLs can be found here: http://codeigniter.com/user_guide/general/urls.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.