重定向所有链接以在主 url 前面包含一个段

发布于 2024-09-17 10:00:36 字数 608 浏览 2 评论 0原文

我使用 mamp 设置了一个本地网站,我在同一 mamp 安装上运行了其他网站,并且我使用我网站上的链接,例如 About

它会将用户定向到 http://localhost/about,但我需要它定向到 http://localhost/chuck/host

chuck 是该站点所在的文件夹,文件路径:/Applications/MAMP/ htdocs/chuck

htaccess 文件中是否有一种方法可以通过将 /chuck 插入 url 的前面来自动重定向任何链接?

我希望这是可能的,所以我不必遍历每个文件并将 /chuck 放在(对于本示例)/about 前面,以使其 http://localhost/chuck/about

I setup a local website using mamp, there are other sites I run in development on the same mamp install and I use links on my site like <a href="/about">About</a>

It will direct the user to http://localhost/about, but I need it to direct to http://localhost/chuck/host

chuck is the folder that this site is within, file path: /Applications/MAMP/htdocs/chuck

Is there a way in the htaccess file that any link automatically is redirected with /chuck plugged into the front of the url?

I hope this is possible, so I do not have to go thru every file and put /chuck in front of (for this example), /about, to make it http://localhost/chuck/about

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

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

发布评论

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

评论(1

彼岸花ソ最美的依靠 2024-09-24 10:00:36
RewriteEngine on
RewriteRule (.*) /chuck$1 [nc,l]

基本上,%{http_host} 之后的任何内容都将放在 /chuck 之后。这将重定向所有内容,使其前面有 /chuck

这必须放在 /path/to/htdocs 文件夹中。但是,这也会导致您无法访问您在那里托管的任何其他网站。

RewriteEngine on
RewriteRule (.*) /chuck$1 [nc,l]

Basically, anything after the %{http_host} will be put after /chuck. This will redirect EVERYTHING to have /chuck in front of it.

This will have to be put in the /path/to/htdocs folder. However, it will also make it impossible to visit any other site you may have hosted there.

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