【问题标题】:URL rewriting-page not found errorURL 重写页面未找到错误
【发布时间】:2009-04-30 12:14:18
【问题描述】:

为了将我的动态 URL 即 www.3idiots.co.in/index.php 转换为静态 URL 即 www.3idiots.co.in/index.html,我编辑了我的 .htccess 文件并将以下代码放入它:

RewriteEngine On
RewriteRule ^index.php$ /index.html [R]

当我将此文件上传到根目录并尝试打开页面时,出现错误

404 页面未找到错误,www.3idiots.co.in/index.html 未找到。

【问题讨论】:

  • 好吧,我去了3idiots.co.in/index.html,果然,该页面不存在。你检查你的文件权限了吗?也许 HTTPD 用户看不到它。
  • www.3idiots.co.in/index.php 转到此页面...我想将其转换为 www.3idiots.co.in/index.html

标签: php url mod-rewrite url-rewriting


【解决方案1】:

您实际上必须有一个名为 index.html 的文件。现在你没有。重写/重定向工作正常,您只是重定向到一个不存在的页面/文件。

我对你实际上想要做什么感到有点困惑。如果您只想将 index.php 移动到 index.html,请重命名该文件。重写使得如果有人试图打开 index.php,他们将被重定向到 index.html,但您仍然必须有一个 index.html 文件才能将他们重定向到

【讨论】:

    【解决方案2】:
    RewriteEngine On
    
    # Send the user to index.html
    RewriteRule ^index.php$ /index.html [R]
    
    # Tell the server that index.html really means index.php
    RewriteRule ^index.html$ /index.php
    

    【讨论】:

    • 嘿,格雷格,谢谢你的关心....我试过这段代码,但在浏览器中它显示 www.3idiots.co.in/index.php,但我想要它在 html 中跨度>
    【解决方案3】:

    试试这些规则:

    RewriteCond %{THE_REQUEST} ^GET\ /index\.php
    RewriteRule ^index\.php$ /index.html [L,R=301]
    
    RewriteRule ^index\.html$ index.php [L]
    

    第一条规则将外部/index.php 的每个直接请求重定向到/index.html。第二条规则将/index.html内部的请求重写为/index.php

    【讨论】:

    • 嘿秋葵......它不工作的伙伴......你有任何其他解决方案吗??????????????
    • 您确定 mod_rewrite 已加载并正常工作吗?您是否尝试过更简单的规则(例如 RewriteRule ^ http://example.com/ [R])来查看它是否有效?
    • 希望你没有忘记必填的RewriteEngine on
    【解决方案4】:

    您确定 mod 重写已启用并正常工作吗?

    1) 创建一个名为 found.html 的 html 页面,其中包含您想要的任何内容,但需要一些文本以确保它已加载(基本上不是空白页面)并将其放入名为“.htaccess”的文件中:

    重写引擎开启
    重写基础 /
    RewriteRule ^find.html$ /found.html [L]

    2) 将您的 .htaccess 和 found.html 文件上传到您域的根目录中

    3) 只需尝试加载 -www.example.com/find.html(当然是您的真实域名)。如果 mod_rewrite 可用,您应该在浏览 find.html 时看到 found.html 的内容(顺便说一下,它实际上并不存在)。

    如果不行,试试:

    重写引擎开启
    重写基础 /
    RewriteRule ^find.html$ found.html [L]

    【讨论】:

      【解决方案5】:

      在 Apache Conf 文件中,您还需要确保将 AllowOverride 设置为允许处理 .htaccess 的值。

      通常是 AllowOverride all

      【讨论】:

        【解决方案6】:

        重写引擎开启

        重写规则 ^index.html$ index.php

        重写规则 ^$index.htm/$index.php [L]

        【讨论】:

          【解决方案7】:

          选项 +FollowSymLinks
          重写引擎开启
          重写规则 ^index.html$ index.php

          试试这个代码...

          它会解决你的问题/..

          祝你好运
          如果它能解决您的问题..
          访问我的网站

          【讨论】:

            猜你喜欢
            • 2011-11-14
            • 2019-12-24
            • 2019-11-20
            • 1970-01-01
            • 2016-04-09
            • 1970-01-01
            • 2015-06-22
            • 1970-01-01
            • 2013-08-13
            相关资源
            最近更新 更多