views:

8020

answers:

2

I have seen this in a few .htaccess examples

RewriteBase /

It appears to be somewhat similiar in functionality to the <base href=""> of HTML.

I believe it will automaticlally prepend it's value to the begining 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?

Thanks

+1  A: 

It doesn't prepend, it replaces the relative path.

You really should just carefully read the docs.

chaos
A helpful direct answer sadly marred by the unecessary critism in the second sentence. Okay the guy didn't read something. Do you answer all questions with the same point? They're on here to ask questions not get whacked with a dunce's cap because you think they're being a bit stupid.
Jay Wilde
God, QQ. I told him to read the docs, what a *meanie*.
chaos
+1  A: 

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

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]

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 to http://www.example.com/~new/page/. By having the RewriteBase there, you make the relative path come off the RewriteBase parameter.

alex