zkvvoob
zkvvoob

Reputation: 466

Move website to subdirectory

I'm working on a new version of a website and I'd like to move the files/folders of the old one to a subdirectory 'old'. Is there a way to keep all links (css, references to "includes" folder and files, etc.) working using a redirect rule, instead of having to manually edit all php files?

Thanks!

Upvotes: 2

Views: 142

Answers (2)

anubhava
anubhava

Reputation: 785008

You can move all the old files to a directory old and then have a rewrite rule in root .htaccess like this:

RewriteEngine On
RewriteBase /

# if file exists inside old then append /old/ in front of it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/old/$1 -f [NC]
RewriteRule ^(.+?)/?$ old/$1 [L]

Upvotes: 2

Jester
Jester

Reputation: 1408

No, not as far as i know.

If you use phpstorm you can refactor references easily over all pages, this might fix your problem.

For future projects, it's good practice to use a variable $absolutePath = "C:\...\" and save the path to the main directory in it, and use that variable in all files.

to link to an image you would do as following:

$imagepath = $absolutepath."subdirectory\image.jpg";

If you move your website you only have to change the one variable. This is also something you should think about with other frequent used variables like mysql information.

Upvotes: 0

Related Questions