4

Situation:

I'm moving a website from a production environment to a test environment.

The test environment url is similar to http://192.168.1.100/~username/

There are thousands of files which use the following within the html

<img src='/images/image.jpg' />

Since the request is going to root http://192.168.1.100/ the files are 404.

Rather than finding and replacing all of html I'd assume that there is an easy way to fix it with mod_rewrite via .htaccess.

I've tried using the following

RewriteCond %{REQUEST_URI} !^/~username/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~username/$1

But did not work as expected.

Thanks in advance.

UPDATE The development environment resides within cpanel/whm. So when the username is removed from the requested url, it now belongs to the root users. So, my question now: How do I update the .htaccess file for the root user to mod_rewrite back to the ~username?

  • How is it not working as expected? The rules look fine, in a blank htaccess file, they work fine. – Jon Lin Oct 12 '12 at 18:03
  • Perhaps because ~username is a vhost, and when the file is requested as http://192.168.1.100/, it is looking under the root user. Maybe I just answered my own question – user1741912 Oct 12 '12 at 18:32

1 Answers1

0

If you remove

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

it appears to work as expected, because any request to the right url will not be rewritten.

you might want to add [L] as a flag to signify it's the last rewrite rule, like so:

RewriteCond %{REQUEST_URI} !^/~username/
RewriteRule ^(.*)$ /~username/$1 [L]
JKirchartz
  • 17,612
  • 7
  • 60
  • 88