views:

678

answers:

2

Here is the begining of my .htaccess

   # invoke rewrite engine
        RewriteEngine On
        RewriteBase /~new


    # force non domain.com to www.domain.com

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NC]

everytime I request http://www.example.com/~new/whatever I am sent to http://www.example.com/whatever . I placed brackets around the $1 and I get http://www.example.com/[whatever].

Why is it stripping out my RewriteBase var ?

Or, is there a way to set an environmental variable in .htaccess that I can set RewriteBase to and also put in front of the $1 to make the redirection work?

A: 

just do sth. like this at the BEGINNING of the file, set the rewrite base later

RewriteCond %{HTTP_HOST} ^webmaster-eye\.de$
RewriteRule ^(.*)$ http://www.webmaster-eye.de/$1 [L,R=301]
Tobiask
That did not work sorry :(
alex
+2  A: 

Well, that's kind how RewriteBase works: it blows away all leading path information from your request, and then reinserts the RewriteBase afterward. But in your example, it can't perform the reinsertion because you're giving it a redirect to a fully-qualified URL.

I think you should back up and define exactly what you're trying to do, and possibly ask a new question about that, instead of assuming that RewriteBase is what you need to be using and focusing on "why isn't RewriteBase doing what I want". RewriteBase may be nothing to do with it.

chaos
My site is currently sitting in a /~new/ off the top level domain, but when it goes to production it will simply be the TLD. I want a way of informing my .htaccess once that the site is located in a subdirectory, and then later change to RewriteBase / when I switch to the TLD.
alex
... and have everything work straight away simply by changing `RewriteBase /~new` to `RewriteBase /`
alex
All right. Here's my question, I suppose: if you just take out the RewriteBase, what behavior do you get that constitutes a problem?
chaos
The same thing! Thanks for your answer, much appreciated, but I ended up asking a new question http://stackoverflow.com/questions/708305
alex