Ganesh Rathinavel
Ganesh Rathinavel

Reputation: 1335

Restrict the url_suffix in codeigniter

I am using codeigniter 2.1.4 and I have set $config['url_suffix'] = ".html";

It's working fine with out any trouble. But I found out that if I use redirect(); function will always add url_suffix on the landing page url. eg: site.com/login/success.html.

My question is there anyway to exclude the url_suffix while using the redirect() function? or is there anyway to add .html without setting url_suffix in codeigniter, may be some hack in .htaccess??

I tried to add

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html

in the project htaccess file, but once i unset the url_suffix variable the framework throws 404 error. Any work around?

Thanks :)

Upvotes: 4

Views: 2171

Answers (1)

Hashem Qolami
Hashem Qolami

Reputation: 99534

You could leave the url_suffix config blank $config['url_suffix'] = ''; and define specific routes to add .html suffix to some cases.

For instance, for the blog posts:

In routes.php (which is located at application/config/ by default):

$route['blog/(.+)\.html'] = "posts/view_post/$1";
/*                           ^     ^         ^
                             |     |         |
                Controller ---   Method      --- Post SEO url or ID
*/

Upvotes: 5

Related Questions