正在建设中的网站页面,无需重定向

发布于 2024-08-17 13:35:41 字数 518 浏览 12 评论 0原文

我想知道是否有某种方法可以更改一些简单的内容,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

錯遇了你 2024-08-24 13:35:41

为此,我们使用 apache mod_rewrite。
它检查maintenance.html 文件是否存在,如果存在,则提供该页面。

要打开它,我们只需执行以下操作:

> mv maintenance.html.bak maintenance.html 

并再次隐藏它:

> mv maintenance.html maintenance.html.bak 

这是为此的 httpd.conf:

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

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:

> mv maintenance.html.bak maintenance.html 

and to hide it again:

> mv maintenance.html maintenance.html.bak 

Here is out httpd.conf for this:

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
木槿暧夏七纪年 2024-08-24 13:35:41

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文