在我的网站中,有三到四种类型的URLS (每种类型都可以有不同的参数来表示不同的页面)。它们就像http://foo.com/users/username、http://foo.com/questions/question_text、http://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/。有没有这样的指令可以实现这种包罗万象的重定向?
发布于 2012-09-22 04:30:41
还有很长一段路要走:
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错误,并且如果请求的页面不存在,则提供自定义错误页面,则会友好得多。此外,如果您这样做,并且您的站点必须通过第三方安全扫描,那么您将为报告生成大量的误报安全漏洞。
https://stackoverflow.com/questions/12536769
复制相似问题