Rewrite URL in codeigniter

232 Views Asked by At

How can I completely avoid using the Codeigniter method of handling URLs and use the conventional way?

Instead of [root_url]/index.php/controller/view/data, how can I just get [root_url]/view.php?variable=value&variable=value etc ....

If it matters, I am running and testing the site locally and not on the net.

1

There are 1 best solutions below

0
On BEST ANSWER

If you're not intending on using CI for its URL handling, I would probably recommend using a different framework.

I would recommend keeping your entire application within the CodeIgniter scope. [base_url]/view/?param=value works just fine, and you can access GET requests via $this->input->get('param');

Another option is enabling enable_query_strings, which gives you some control over how controllers/functions are routed. Have a look at enable_query_strings in the documentation on URLS at http://codeigniter.com/user_guide/general/urls.html

Alternatively, If you don't want view.php in your CI app, [base_url]/view.php?param=value&etc= should load, but it'll exist outside the CodeIgniter scope.

If it's not loading, make If you have an .htaccess file and are redirecting traffic, make sure you have !-f and !-d flags for the REQUEST_FILENAME enabled, so that view.php isn't being redirected:

$RewriteCond %{REQUEST_FILENAME} !-f
$RewriteCond %{REQUEST_FILENAME} !-d
$RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]