Welcome Guest, Not a member yet? Register   Sign In
Using Mod_Rewrite and _Remap in 2.x
#1

[eluser]Lakestone[/eluser]
I have an old CI application that I'm trying to port to the latest version.
All I want to is to take in the first segment of the welcome page and then remap:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Start extends CI_Controller
{
public function _remap($uri)
{
  if($uri == 'contact')
   $this->contact();
}
public function contact()
{
  $this->load->view('contact');
}
public function index()
{
}
}

Since 'Start' is my main controller, the url will look like "localhost/app1/". And if I type into the address bar "localhost/app1/contact" it should use the main controller but call the contact function.

Can I accomplish this without using mod rewrite? If not, this is the current .htaccess code that I use:
Code:
RewriteEngine On
RewriteBase //
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/Start/$1 [L]

What else is missing? I keep getting "Not Found - The requested URL /index.php/Start/contact was not found on this server."

Cheers
#2

[eluser]Aken[/eluser]
Mod rewrite is meant to remove the index.php function only, so you can remove anything specific involving your app from that.

There's a lot of different ways to handle and direct requests - you should explain more about what pages do and don't need to be routed, because using a single controller function to handle requests can be cumbersome and often unnecessary.
#3

[eluser]Lakestone[/eluser]
Hi Aken,
I'd like to be able to use more than one controller for sure. But right now I cannot seem to access any other method inside my controller by using the URL app1/controller/method, I still have to (even with the mod rewrite), use app1/index.php/controller/method.

So do I need to update my htaccess file or is the problem laying somewhere else?
#4

[eluser]Aken[/eluser]
Your .htaccess is the problem. Try this:

Code:
RewriteEngine On

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

[eluser]Lakestone[/eluser]
[quote author="Aken" date="1331075940"]Your .htaccess is the problem. Try this:

Code:
RewriteEngine On

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

Same result, but shorter:
http://localhost/start/contact

Not Found
The requested URL /index.php/contact was not found on this server.
#6

[eluser]CroNiX[/eluser]
Do you have any routes? You request /start/contact but it looks like it's going straight to contact, so it looks like a route or something might be interfering.
#7

[eluser]Lakestone[/eluser]
The only route I am using is: $route['default_controller'] = "start";

If you got a clean install of CI with necessary tweaks like a .htaccess file - that is working like I want it, feel very free to zip it and upload it.
I'd be extremely thankful, this is starting to annoy me quite a bit now Sad




Theme © iAndrew 2016 - Forum software by © MyBB