gpt4 book ai didi

.htaccess - 使用 URL 重写时出现问题(相对路径不起作用)

转载 作者:行者123 更新时间:2023-12-01 03:00:27 26 4
gpt4 key购买 nike

我正在使用 .htccess 文件来重写我的 URL。我在我的 .htaccess 文件中使用了以下规则

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^product/([0-9]+)/([A-Za-z0-9+]+)$ /product.php?productid=$1&prodname=$2

重写工作正常。

但是当我尝试通过相对路径访问任何其他页面时,在所有情况下,URL 都没有正确重定向。

像下面的例子

<form action "something.php" method="post">
<input type="text" name="1" />
<input type="submit" value="submit" />
</form>

当我点击提交时,加载的页面是 http://mydomain/product/1/something/something.php,它不存在,因此抛出 404 错误

我尝试在 head 中使用 base 标签,但这会在我使用页面 anchor 和模式窗口时产生问题。它被重定向到索引页面。

如果需要更多详细信息,请告诉我。

我对此很陌生。那么,有人可以帮我解决这个问题吗?

提前致谢,卡尔提克

最佳答案

这是一个 URL 解析问题。参见 mod_rewrite URL info required了解详情。

您可以使用绝对 URL 路径或绝对 URL:

<form action="/something.php" method="post">
<form action="http://example.com/something.php" method="post">

或者您更改基本 URL(请参阅 BASE HTML element)以便从该 URL 而不是当前 URL 解析每个相对 URL:

<base href="/">
<base href="http://example.com/">

关于.htaccess - 使用 URL 重写时出现问题(相对路径不起作用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/938997/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com