开发者

How to autoload a site through a php file?

开发者 https://www.devze.com 2023-02-08 19:07 出处:网络
Is there a way to use a php file to automatically load a website. I have a new version of my website, but I want to keep the current version live (with its current domain). I would just like to direc

Is there a way to use a php file to automatically load a website.

I have a new version of my website, but I want to keep the current version live (with its current domain). I would just like to direct clients/customers to preview the new version but still be able to go to the current site.

For example: They would go to the current site by visiting www.currentsite.com. And to visit the new version they would visit www.currentsite.开发者_StackOverflow中文版com/newversion

Both sites are subfolders within the root of my hosting account. How do I achieve this?

Thanks for any help on this question.


You probably want to take a look at .htaccess files:

Assuming your current website is located in /home/user/public_html/current and your new website is in /home/user/public_html/new, you could set up something like this:

RewriteEngine On
# Rewrite every uri that does not start with /newversion/ to the current website
RewriteCond %{REQUEST_URI} !^/newversion/?(.*)$
RewriteRule (.+) /current/$1 [NC,L]

# Rewrite everything else to /new
RewriteRule (.+) /new/$1 [NC,L]

Judging from your post and the fact that you are mentioning multiple folders in a hosting account, there is a pretty good chance you already have something like this setup for your current website.

Take a look in your root folder and see if there is a .htaccess file and start editing away.


If you're looking for a PHP-only solution, you can put an index.php or simmilar file at the root folder of the domain containing:

<?php

header("Location: http://www.currentsite.com/current");

?>

That would enable a redirection from http://www.currentsite.com/ to http://www.currentsite.com/current. The drawback is that you'd have to stick with "current" in your path, so I'd go for the more elegant .htaccess solution.

EDIT

Oh, and if you already have an .htaccess file in the root folder doing similar rewriting tasks, chances are this approach won't work as index.php won't ever be reached. You'd better check for that first.


Or create a simple index.html file in the "/newversion" directory with an iframe.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<body>
<iframe src="/" width="100%" height="100%"></iframe>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消