Redirect broken index.html files to home page using htaccess

℡╲_俬逩灬. 提交于 2019-12-12 05:38:55

问题


I want to redirect my broken index.html files from sub folders to home page using htaccess

Example:-

http://blogs.hds.com/hdsblog/category/
http://blogs.hds.com/hdsblog/category/sustainability/page/

are broken links (reported by Google Webmaster). These do not exist.

I want to update my htaccess file, so that URLs like these automatically redirect to the home page of my site.


回答1:


You can use a simple RewriteRule for these URLs

RewriteRule ^hdsblog/category/ / [R,L]

This redirects all requests starting with /hdsblog/category/, including /hdsblog/category/sustainability/page/ to your home page http://blogs.hds.com/.

If you want to redirect only these exact requests, you must specify multiple RewriteRules

RewriteRule ^hdsblog/category/$ / [R,L]
RewriteRule ^hdsblog/category/sustainability/page/$ / [R,L]


来源:https://stackoverflow.com/questions/15481813/redirect-broken-index-html-files-to-home-page-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!