views:

227

answers:

2

I'm running wamp on Vista (Apache v2.2.11) and have projects setup such that http://localhost/projectx is the base directory for projectx. Now, I want that requests for

http://localhost/projectx/somepage/extra

will rewrite to

http://localhost/projectx/PUBLIC/somepage/extra

To that end I have a file in C:\wamp\www\projectx\.htacces that is this simple:

RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC
RewriteRule ^(.*)$ /PUBLIC$1 [L]

I can't for the life of me figure out why this doesn't work. The error I'm getting is "The requested URL /PUBLIC was not found on this server". Thanks.

UPDATE 25-MAR-2010:

As per Michael's solution I removed the absolute path. For some reason I also needed to add a final slash to the Cond and Rule:

RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC/
RewriteRule ^(.*)$ PUBLIC/$1 [L]
A: 

Try changing this: RewriteRule ^(.*)$ /PUBLIC$1 [L]

To this: RewriteRule ^(.*)$ PUBLIC$1 [L]

It's probably just the absolute path that is the problem.

You also need to change the $1 to be zero based so RewriteRule ^(.*)$ PUBLIC$0 [L]

Michael
You fix (almost) works. I'm a little confused though, the first part `^(.*)$` is matching the URI, but the second part with a `/` at the front makes the replacement an absolute path? How does that relate then to `RewriteBase` when it returns the URI path to its pre-base form? Also, I get no error for `/localhost/projectx/` and page is forwarded to `/localhost/projectx/PUBLIC/`, but when I try `/localhost/projectx/extra/` I get a 500 internal server error. Thanks.
Brett Pontarelli
The rewrite base is is the base for your regular expression but the final destination file could be in a separate directory so its path is relative to the .htaccess file's location.
Michael
Thanks. That makes so much more sense now. Also, your solution works with one minor addition (see orig. post).
Brett Pontarelli
A: 

Should be

RewriteEngine On

RewriteBase /projectx

RewriteCond %{REQUEST_URI} !^/PUBLIC

RewriteRule ^(.)(PUBLIC)(.)$ /projectx/PUBLIC$3 [L]

shikhar