如何使用 htaccess 使 http 请求正常工作

发布于 2024-08-25 16:47:21 字数 437 浏览 2 评论 0原文

我目前有 css 和 javascript 文件调用(除其他外),如下所示:

href="/css/default.css" src="/js/ui_control.js"

将前面的 / 放入以使文件相对于根目录。

当我的页面位于域的根目录中时,这非常有效。 但是,我目前正在将我的网站转移到新的托管提供商,因此有一个临时 URL:HOST-IP/~username

因此,所有文件调用都尝试从 HOST-IP/ 调用css/default.css 等而不是在 ~username 子文件夹中。

当然,我可以等到域名服务器传播,但这不是重点。

我将如何在 .htaccess 文件中编写一条规则,将所有以 / 开头的文件调用从 HOST-IP/FILE-CALL 重定向到 HOST-IP/~USERNAME/FILE-称呼。 ?

有什么想法吗?

I currently have css and javascript file calls (amongst other things) like the following:

href="/css/default.css"
src="/js/ui_control.js"

putting the preceding / in to make the files relative to the root.

This works great when my page is in the root of the domain.
However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username

As such, all file calls are trying to be called from HOST-IP/css/default.css etc instead of within the ~username sub-folder.

Of course I can wait until the domain name servers propagate but that's beside the point.

How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

忱杏 2024-09-01 16:47:21

我建议将 HTML 中的引用更改为相对文件,因为这既可以在子文件夹中工作,也可以作为域的根目录工作。

I'd suggest changing the references in your HTML to the files to be relative, as this will work either in a sub folder or as the root of the domain.

酒绊 2024-09-01 16:47:21

当我的页面位于域的根目录中时,这非常有效。但是,我目前正在将我的网站转移到新的托管提供商,因此有一个临时 URL:HOST-IP/~username

我如何在 .htaccess 文件中编写一条规则,将所有以 / 开头的文件调用从 HOST-IP/FILE-CALL 重定向到 HOST-IP/~USERNAME /文件调用。 ?

除非您可以在新服务器上的 HOST-IP/.htaccess 处放置 .htaccess,否则您无法使用 .htaccess 执行此操作。听起来您好像在共享主机上,因此任何允许您使用 .htaccess 执行此操作的方法都将允许您劫持服务器上其他所有人的网站。

This works great when my page is in the root of the domain. However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username

How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?

Unless you can put a .htaccess at HOST-IP/.htaccess on the new server, you can't do this with .htaccess. It sounds like you're on a shared host, so any approach that'd let you do this with .htaccess would allow you to hijack everyone else's site on the server.

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