0

I have a website that I need to move to a subdirectory.

Alias /oldsite /home/server/public_html/oldsite

My question is, is there a way to rewrite all of the requests for absolute paths from the root to the new directory?

For example:

<img src="/images/test.png">

will become:

<img src="/oldsite/images/test.png">

Is there a way to do this with mod_rewrite?

Thanks and any help is much appreciated!

SQL.injection
  • 2,607
  • 5
  • 20
  • 37

1 Answers1

0

You can try something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -d
RewriteRule ^(.*)$ /oldsite/$1 [L]

If that starts with mess with whatever site you happen to have in your document root, you could try checking the referer:

RewriteEngine On
RewriteCond %{HTTP_REFERER} /oldsite/
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -d
RewriteRule ^(.*)$ /oldsite/$1 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220