gpt4 book ai didi

apache - htaccess mod rewrite - 我的一半规则(都相似)不起作用

转载 作者:行者123 更新时间:2023-12-04 18:32:18 25 4
gpt4 key购买 nike

我整天都在为此工作,希望其他人能插手帮助我。

我正在构建一个新站点(在我们的开发服务器上),但我遇到了一些简单的 SEO 友好 URL 的问题。

我只是将一些 SEO 友好的关键字重定向到静态 PHP 页面。我的文件适用于大多数链接,但有 2 个因未知原因而中断。

这是我的文件:

Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteRule ^about-us$ aboutus.php [L]
RewriteRule ^resource-center$ resourcecenter.php [L]
RewriteRule ^our-services$ ourservices.php [L]
RewriteRule ^management-solutions$ ms.php [L]
RewriteRule ^additional-services$ additionalservices.php [L]
RewriteRule ^contact-us$ contactus.php [L]

出于某种原因,资源中心和联系我们将进入 404 页面。当我单击链接时,将在contact-us 和resource-center 添加一个斜杠,但在任何其他链接上都没有。

如果我编辑 htaccess 文件并将 ^resource-center$ 更改为 ^resourcecenter$,它将正常工作。如果我将其更改为 ^resource-center/$ 以考虑添加的尾部斜杠,则页面将加载,但 CSS/JS/图像均未加载。

我在这里很难过,尤其是因为它看起来如此不一致。所有文件都存在,没有会干扰的 htaccess 文件,HTML 或 htaccess 中的所有链接都以相同的方式格式化,但其中 2 个每次都给我错误。

如果有人可以帮助我,将不胜感激。

最佳答案

  • MultiViews选项关闭
  • 允许可选的尾部斜杠

  • 试试这个代码:
    Options +FollowSymLinks -MultiViews

    RewriteEngine on
    RewriteBase /

    RewriteRule ^about-us/?$ aboutus.php [L,NC]
    RewriteRule ^resource-center/?$ resourcecenter.php [L,NC]
    RewriteRule ^our-services/?$ ourservices.php [L,NC]
    RewriteRule ^management-solutions/?$ ms.php [L,NC]
    RewriteRule ^additional-services/?$ additionalservices.php [L,NC]
    RewriteRule ^contact-us/?$ contactus.php [L,NC]

    对于 css/js 等,您可以将其添加到页面的 HTML header 中:
    <base href="/" />

    以便从 / 解析每个相对 URL而不是来自当前页面的 URL。

    关于apache - htaccess mod rewrite - 我的一半规则(都相似)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27304878/

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