Apache重写规则(url重写)
例如,如何进行网址重写,我希望我的看起来像
www.myurl.com/study-abroad/what/ever/
如果我输入
www.myurl.com/studyabroad/what/ever/
想法是有留学而不是留学
How can make a url rewriting for example, I want my to look like
www.myurl.com/study-abroad/what/ever/
If I type
www.myurl.com/studyabroad/what/ever/
The idea is to have study-abroad instead of studyabroad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您提前知道每个 URL 将遇到多少个破折号,则可以完成此操作:
...等等。不过,我可以补充一点,这是设计所破坏的,您应该重新考虑您的方法。
问候
It can be done if you know in advance with how many dashes per URL you'd be confronted:
... and so forth. May I add, though, that this is broken by design and you should reconsider your approach.
Regards
对于这样一个简单的示例,我将使用
mod_alias
重定向而不是mod_rewrite
。示例:请参阅 http://httpd.apache.org/docs/2.0/ mod/mod_alias.html#redirect 获取完整文档。
您需要将此(或类似的)代码片段放入 Apache 配置文件中:如果启用(并且您有适当的权限),这可能是您网站目录中的
.htaccess
。或者,您可以修改 Apache 主配置。请参阅http://httpd.apache.org/docs/current/configuring.html 有关 Apache 配置文件的信息。(编辑以反转映射:添加破折号而不是删除它)
For such a simple example I would use
mod_alias
Redirects rather thanmod_rewrite
. Example:See http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirect for the full documentation.
You need to put this (or a similar) snippet into an Apache configuration file: if enabled (and if you have appropriate permissions), this might be
.htaccess
in your website's directory. Or, you could modify the master Apache config. See http://httpd.apache.org/docs/current/configuring.html for information about Apache configuration files.(edited to invert the mapping: adding a dash instead of removing it)