首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MOD_Rewrite指令来实现catchall重定向

MOD_Rewrite指令来实现catchall重定向
EN

Stack Overflow用户
提问于 2012-09-22 03:10:44
回答 1查看 60关注 0票数 1

在我的网站中,有三到四种类型的URLS (每种类型都可以有不同的参数来表示不同的页面)。它们就像http://foo.com/users/usernamehttp://foo.com/questions/question_texthttp://foo.com/new_question等。

我使用mod_rewrite重写来自客户端的URL,也就是说,http://foo.com/users/username变成了http://foo.com/users?username=username,然后这个请求转到了http://foo.com/users,它完成了剩下的工作。

现在我希望,除了这些3-4个预定义的模板,如果任何其他请求到来,如http://foo.com/abracadabra,用户应该被重定向到主页http://foo.com/。有没有这样的指令可以实现这种包罗万象的重定向?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-22 04:30:41

还有很长一段路要走:

代码语言:javascript
复制
RewriteEngine On
# If the request isn't actually a file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request isn't actually a directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request isn't specifically for favicon.ico (though the first 
# RewriteCond should take care of this, it's in the first .htaccess file
# I grabbed to verify)
RewriteCond %{REQUEST_URI} !=/favicon.ico
# Change the request from whatever the user entered to "/"
RewriteRule ^(.*)$ /

但你真的不该这么做。如果您实际提供404错误,并且如果请求的页面不存在,则提供自定义错误页面,则会友好得多。此外,如果您这样做,并且您的站点必须通过第三方安全扫描,那么您将为报告生成大量的误报安全漏洞。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12536769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档