Welcome Guest, Not a member yet? Register   Sign In
Redirections with .htaccess
#1

[eluser]Razican[/eluser]
Hello, I have a controller named error.php which controls all the erros like "Incorrect password" or "Incorrect email" with the function index.

If I want to show the "Incorrect password" error, I have to redirect the user to example.com/error/index/1 or example.com/error/index/2 for the email error.

I would like to remove the /index part of the URI with .htaccess, like I did with the /index.php/ part. How can I do it?

I have tried to add this in the .htaccess file but it doesn't work:
Code:
RewriteRule ^error/([0-9]+) error/index/$1
#2

[eluser]mddd[/eluser]
You don't need to do any .htaccess redirection for that. Use the _remap() method in your controller to show the right info without putting the name of the index() method in the url.

Check out the page on Controllers and remapping.

Code:
class Error extends Controller
{
  function __construct()
  {
    parent::__contruct();
  }
  function _remap($x)
  {
    switch ($x)
    {
      case 1:
        // show password error
      break;
      case 2:
        // show email error
      break;
    }
  }
}
#3

[eluser]Razican[/eluser]
Code:
function __construct()
    {
        parent::__contruct();
    }

That code is the same as this?
Code:
function Error()
    {
        parent::Controller();    
    }
#4

[eluser]mddd[/eluser]
Yes. The __construct() is for php5. Error() works for php4 and php5 (if the name of the class is Error).
#5

[eluser]Razican[/eluser]
And which is faster? Because I want to make a the fastet app as posible.
#6

[eluser]mddd[/eluser]
I don't think there is any difference between the two. Both will be tried when the class is instantiated.
#7

[eluser]Razican[/eluser]
OK Thanks, now it works!




Theme © iAndrew 2016 - Forum software by © MyBB