开发者

How do i render .php URL with .html extension

Hi i am using Codeigniter PHP framework.

Is there is any way to display .html extension rather than .php exten开发者_开发百科sion in URL?


Set your url suffix on your config.php found here

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


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


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


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.


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

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜