如何在.htaccess的RewriteBase工作 [英] How does RewriteBase work in .htaccess

查看:727
本文介绍了如何在.htaccess的RewriteBase工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这几个的.htaccess 例子

RewriteBase /

这似乎是在功能上与&LT有几分相似,基地的HREF => 的HTML。

我相信它可能会自动prePEND其值的重写规则语句开始(可能是那些没有前导斜杠)?

I believe it may automatically prepend its value to the beginning of RewriteRule statements (possibly ones without a leading slash)?

我不能让它正常工作。我认为它的使用可以派上非常方便现场的便携性,因为我经常有一个开发服务器是不同的,以一个生产企业之一。我目前的方法给我留下删除部分脱离我的重写规则语句。

I could not get it to work properly. I think it's use could come in very handy for site portability, as I often have a development server which is different to a production one. My current method leaves me deleting portions out of my RewriteRule statements.

谁能给我解释一下简要如何实现的呢?

Can anyone explain to me briefly how to implement it?

感谢

推荐答案

在我自己的话,阅读文档和试验后:

In my own words, after reading the docs and experimenting:

您可以使用的RewriteBase 提供的基础的你重写。考虑这个

You can use RewriteBase to provide a base for your rewrites. Consider this

# invoke rewrite engine
    RewriteEngine On
    RewriteBase /~new/

# add trailing slash if missing
    rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]

这是一个真正的规则,我用它来确保URL都有斜线。海事组织,它看起来更加整洁。这将转换

This is a real rule I use to ensure that URLs have a trailing slash. IMO, it looks neater. This will convert

http://www.example.com/~new/page

http://www.example.com/~new/page/

由于具有的RewriteBase 在那里,你做的相对路径来关闭的RewriteBase 参数。

By having the RewriteBase there, you make the relative path come off the RewriteBase parameter.

这篇关于如何在.htaccess的RewriteBase工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆