如果在重写的URL中找不到页面,如何重定向到特定页面 [英] How to redirect to a particular page when page is not found in rewritten url

查看:97
本文介绍了如果在重写的URL中找不到页面,如何重定向到特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在开展一个项目,我有一个搜索结果页面。我已经重写了网址。



我的网址:



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



现在这里如果从网址中移除最后一部分(在/之后)即

www.xyz.com/city/area/search/category我收到错误404页面未找到。



如何通过重定向用户来避免此错误到现有的页面。



我知道这是可能的



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>





但是在所有情况下都可以重定向

< br $>
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 /



我是否必须为每种可能性创建页面?



请指导。< br $>


谢谢



我的尝试:



我在webconfig中使用的规则



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>

推荐答案

/>
< action type =Rewriteurl ?=/ searchresults.aspx城市= {R:1}&安培;面积= {R:2}&安培;类型= {R:3}&安培;查询= {R:4}&安培; CC = {R:5} redirecttype =Permanent/>
< / rule>
" /> <action type="Rewrite" url="/searchresults.aspx?city={R:1}&area={R:2}&type={R:3}&query={R:4}&cc={R:5}" redirecttype="Permanent" /> </rule>


你不应该这样做,它打破了互联网的规则如果网址不存在,那么它需要返回404以便调用服务可以正确处理它。如果你没有404你的网址,那么搜索引擎会认为每个不存在的网址都是相同的html,这可以作为重复内容对你不利。



你应该做的是实现一个自定义404页面,其上有一些功能,如搜索框,或查看类别列表等。
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.


这篇关于如果在重写的URL中找不到页面,如何重定向到特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆