我是 htaccess 的新手。我正在使用 Keystone.js,我使用它开发了一个正在侦听端口 3000 的博客。像这样:
https://localhost:3000
现在一切都很好。但我想要的是我的博客应该在这个 url 上运行:
https://localhost/blog
如何在我提供“ https://localhost/blog ”的情况下实现这种情况,它应该像“ https://localhost:3000 ”一样工作。在这种情况下,URL 将保持不变:https://localhost/blog
另外,我还希望当用户访问此 url:“ https://localhost:3000 ”时,它应该重定向到:“ https://localhost/blog ”。
我怎样才能实现这种情况?我想要的只是从 URL 中隐藏一个端口。
我已经尝试了很多事情来解决,但它不适合我。像这样的东西:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^blog(.*) http://localhost:3000/$1 [P,L]
好的,现在这个关于代码的代码非常适合主页,即:https://localhost/blog,因为我在 htaccess 中为它添加了一条规则。但问题是我的博客中的所有链接、图像和包含的文件都已损坏。
现在我为这个问题使用了基本标签。但它将我的链接转换为这种格式:
http://localhost:3000/contact
http://localhost:3000/help
http://localhost:3000/post
我认为http://localhost:3000/作为我页面标题中的基本标记。如您所见,3000 端口再次出现在我不想显示的 url 中。它应该是:
http://localhost/blog/contact
http://localhost/blog/help
http://localhost/blog/post