Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone

I am working on a project where I have a search results page. I have rewritten the url.

My url:

www.xyz.com/city/area/search/category/cs-tCbQIY8hMYQ-TT-3d

Now here if remove the last part from the url (after the /) i.e.
www.xyz.com/city/area/search/category I get an error 404 page not found.

How can I avoid this error by redirecting the user to an existing page.

I know this is possible

<customErrors mode="RemoteOnly" defaultRedirect="~/Error">
   <error statusCode="500" redirect="~/Error" />
   <error statusCode="404" redirect="~/NotFound" />
</customErrors>


But is it possible to redirect in all situations

www.xyz.com/city/area/search/category/cs-tCbQIY8hMYQ-TT-3d
www.xyz.com/city/area/search/category/
www.xyz.com/city/area/search/
www.xyz.com/city/area/
www.xyz.com/city/

Do I have to create page for each possibility?

Please guide.

Thanks

What I have tried:

The rule I am using in webconfig
<rule name="city and category">
<match url="^([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)$" />
<action type="Rewrite" url="/searchresults.aspx?city={R:1}&area={R:2}&type={R:3}&query={R:4}&cc={R:5}" redirecttype="Permanent" />
</rule>
Posted
Updated 12-Sep-16 3:51am
v2

1 solution

You shouldn't do that, it breaks the rules of the internet and can have SEO consequences for you. If the url does not exist then it needs to return 404 so that calling services can handle it correctly. If you didn't 404 your urls then search engines would think every non-existent url has the same html and that can count against you as duplicate content.

What you should do instead is implement a custom 404 page that has some functionality on it like a search box, or to look at the category lists etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900