0

Original URL

mydomain.com/main/portfolio

Now I need to remove the controller name from the URL with the below Route which i have done successfully:

//Controller Name: main
$route['(:any)'] = "main/$1";

My new URL is good:

mydomain.com/portfolio

But the original URL is still accessible which I don't want for SEO purposes:

mydomain.com/main/portfolio

How can I have my good URL run as normal and block the old URL.

Thanks.

1
  • 1
    you can use .htaccess for this Commented Apr 22, 2016 at 6:50

2 Answers 2

1

You can create a not found page and redirect unwanted routes to that. For instance you can create error controller:

class Error extends CI_Controller {     
    public function error_404() {
        // send 404 header
        $this->output->set_status_header('404');
        // load a custom not found page view template
        $this->load->view('error_404');
    }        
}

Then in the routes.php you can catch those URLs which contains the "main/" like this:

// this should be placed above the (:any) route
$route['main/(:any)'] = 'error/error_404';
$route['(:any)'] = "main/$1";
Sign up to request clarification or add additional context in comments.

1 Comment

Is that ok for SEO?
0
RedirectMatch "^/main/(.*)" "http://www.example.com/$1"

More examples available here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.