在服务器中移动文件夹时,更正所有链接

发布于 2024-09-27 08:34:40 字数 310 浏览 7 评论 0原文

假设我的服务器上有一个名为 books 的文件夹。

在里面我有一个带有以下链接的index.php: 书籍/book1.php books/book2.php

然后我决定创建一个名为“scifi”的子目录,以便更好地对书籍进行排序。

所以这些书不在: 书籍/科幻/book1.php books/scifi/book2.php

链接已更改,现在 index.php 上的链接不起作用。

我怎样才能(或重定向*)所有链接而不必一一浏览。

*请不要被重定向抛弃,我并不是以编程方式(必然)而是以说明性方式表示它。

Lets say I have this folder on my server called books.

Inside I have and index.php with this links:
books/book1.php
books/book2.php

I then decide to create a subdirectory called "scifi", for a better sorting of the books.

So the books are no in:
books/scifi/book1.php
books/scifi/book2.php

The links have changed and now the links on index.php dont work.

How can I (or redirect*) all the links without having to go one by one.

*please dont be thrown away by redirect I do not mean it in the programming way (necessarily) rather in an illustrative one.

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

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

发布评论

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

评论(2

触ぅ动初心 2024-10-04 08:34:40
$sampleLink = "books/book1.php";

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"
$sampleLink = "books/book1.php";

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"
弃爱 2024-10-04 08:34:40

只是为了澄清史蒂夫的回答:

<?php

$sampleLink = '<a href="/book1.php">Book...</a>';

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/email/books/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"

echo $sampleLink;
?>

这作为一堂课确实很有用,但我没有将链接定义为 php 变量,所以工作是一样的!

非常感谢你!

Just to clarify Steve´s answer:

<?php

$sampleLink = '<a href="/book1.php">Book...</a>';

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/email/books/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"

echo $sampleLink;
?>

It was really useful as a lesson but i didn´t have the links links defined as php variables so the work would be the same!

Thanks you very much!

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