Question

I am using cakphp1.3 My question Its a property listing site. For an individual property showing i have the following url http://srighar.com/property/view/66/1BHK-Test1-in-attingal-Ranchi-Jharkhand-for-sale But the same page will appera for all the following urls http://srighar.com/property/view/66/1BHK-Test1-in-attingal-Ranchi-Jharkhand-for mysite//srighar.com/property/view/66/1BHK-Test1-in-attingal-Ranchi mysite//srighar.com/property/view/66/1BHK-Test1-in-attingal-Ran .....etc... mysite//srighar.com/property/view/66/

I need to maintain the first url(/property/view/66/1BHK-Test1-in-attingal-Ranchi-Jharkhand-for-sale) for all the above urls if the user accidently delete the characters on the url.

Was it helpful?

Solution

Check the url and redirect if necessary

All you need to do is check that the slug in the url is the current slug, and if not, 301 redirect to the right url:

function view($id, $slug = null) {
    $record = $this->Foo->findById($id);
    if ($record['Foo']['slug'] !== $slug) {
        return $this->redirect(
            array(
                $id,
                $record['Foo']['slug']
            ),
            301
        );
    }

    ...
}

That way, if the slug is accidentally wrong, or if the slug changes (original record updated) the url is maintained correct and there is an enforced canonical url for each record.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top