Apache mod-rewrite 缩短 url
是否可以使用 mod-rewrite 做类似的事情?
当前 url:
www.example.com/Departments/dynamicPage.php?DeptID=10&DeptName=HR
设置重写,以便:
www.example.com/hr
可以重定向到上面(带有参数)?
我知道我可以在根级别创建一个“hr”文件夹,并放入一个带有元刷新的 html 页面,但我讨厌额外的混乱。
我认为 .htaccess 301 是不可能的,但如果我错了,请纠正我。我正在寻找一个可以添加到未来实例的优雅解决方案。
Is it possible do do something like this with mod-rewrite?
Current url:
www.example.com/Departments/dynamicPage.php?DeptID=10&DeptName=HR
to set up a rewrite so:
www.example.com/hr
could redirect to the above (with the arguments)?
I know I could create an "hr" folder on the root level and put in an html page with a meta refresh, but I hate the extra clutter.
I don't think a .htaccess 301 is possible, but please correct me if I'm wrong. I'm looking for an elegant solution that can be added to for future instances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来很合理。类似的事情应该可以解决问题:
如果你想让它变得通用:
当然,那么你需要小心那些前往实际上不存在的部门的人,并且你需要确保你的所有部门名称有意义。
如果您想要 301 重定向,请在重写规则末尾使用
[R=301]
或[L,R=301]
。Seems reasonable. Something along the lines of this should do the trick:
If you want to make it generic:
Of course, then you need to be careful about people heading to departments which don't actually exist, and you'll need to make sure all your DeptNames make sense.
If you want a 301 redirect, use
[R=301]
or[L,R=301]
at the end of the rewrite rule.