正在建设中的网站页面,无需重定向
我想知道是否有某种方法可以更改一些简单的内容,例如 htaccess 文件、js 文件或 php 文件,然后我网站上的所有网页都会显示正在建设中的页面。如果用户必须重定向,我并不太关心,但我希望页面的原始 URL 显示在地址栏中(而不是“正在建设”页面的 URL),并且我希望用户被重定向在执行其他任何事情之前,例如 JS 函数,甚至页面加载。
任何帮助将不胜感激!
谢谢你!
--编辑--
好吧,我已经弄清楚如何重定向用户,而且效果很好。现在,我唯一的问题是,如何使正在建设的页面的网址显示为原始页面?我想做的是,如果用户访问 mysite.com/page.html,我希望用户被重定向到 mysite.com/underconstruction.html,但我希望他们将 mysite.com/page.html 视为地址栏中的地址。有什么想法吗?我对 mod_rewrite 不太确定。我现在正在查找一些教程,但我只是在学习如何编辑 htaccess,而 mod_rewrite 对于初学者来说似乎有点复杂,所以如果你为我简化一点,它会有很大帮助。
I wanted to know if there is some way to change something simple, such as a htaccess file, a js file, or a php file, and then all of the webpages on my site will show an under construction page. I do not really care all that much if the user has to be redirected, but I want the origonal url of the page to be displayed in the address bar (not the one of the Under Construction page) and I want the user to be redirected before anythign else is executed, such as JS functions, or even the page loading.
Any help would be greatly appreciated!
Thank you!
--EDIT--
Ok, so I have figured out how to redirect the user, and it works great. Now, my only problem is, how do I make the url of the under construction page, appear as the original page? What I want to do, is if the user goes to mysite.com/page.html, I want the user to be redirected to mysite.com/underconstruction.html, but I want them to see mysite.com/page.html as the address in the address bar. Any ideas? I am not so sure about the mod_rewrite. I am looking up a few tutorials right now, but I am just learning how to edit the htaccess, and mod_rewrite seems a bit complicateed for a beginner, so if you dumb it down a bit for me, it would help out alot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,我们使用 apache mod_rewrite。
它检查maintenance.html 文件是否存在,如果存在,则提供该页面。
要打开它,我们只需执行以下操作:
并再次隐藏它:
这是为此的 httpd.conf:
We use apache mod_rewrite for this.
It checks to see if a maintenance.html file exists, and it it does, serves up that page.
To turn it on, we just do:
and to hide it again:
Here is out httpd.conf for this:
htaccess 绝对是最佳选择。
至少它满足了你的“我希望用户在执行任何其他操作之前被重定向,例如 JS 函数,甚至页面加载”。
我不能确定它是否会显示原始 URL,您需要尝试一下。
就我个人而言,我的整个网站都是 PHP 的,每个页面都是一个模板,其中包括 header.php、css.php、menu.php 和 footer.php,所以对公共包含文件的(可能是一行)更改就是我想要的需要。我只是提到它,因为您似乎完全重新设计了您的网站,并且可能想要考虑做类似的事情(如果您不热衷于原始 PHP,请查看像 Smarty 这样的临时系统)
htaccess is definitley the way to go.
At least it fullfills your "I want the user to be redirected before anythign else is executed, such as JS functions, or even the page loading".
I can't say for sure if it will display the original URL, you'll need to try that out.
Personally, my whole site is PHP and each page is a template, which includes header.php, css.php, menu.php, and footer.php, so a (possibly one line) change to common include file is all that I would need. I only mention it since you seem to be totally redesigning your website and might want to consider doing something similar (if you are not keen on raw PHP, look at a tempalting system like Smarty)