【问题标题】:.htaccess error : The requested URL was not found on this server.htaccess 错误:在此服务器上找不到请求的 URL
【发布时间】:2017-09-09 17:21:24
【问题描述】:

我有一个 php 文件,它是 home.php

我在本地主机上的网址是

http://localhost:8888/photo/home.php

我想从网址中删除.php

所以我创建了.htaccess 文件

RewriteEngine On

RewriteRule ^home?$ home.php

但我不断收到此错误

在此服务器上找不到请求的 URL /photo/home。

【问题讨论】:

  • ^ 表示从字符串的开头开始搜索。你可能想要^/?photo/home
  • 你好@Cfreak。感谢您的回复,但这也不起作用RewriteRule ^/?photo/home home.php
  • 你可能需要使用这个:RewriteRule ^(/?photo)/home $1/home.php/photo 需要在重写的 URL 中。反向引用的原因是,匹配的 URL 的开头可能有也可能没有斜杠,具体取决于此 RewriteRule 所在的位置。

标签: php apache .htaccess url


【解决方案1】:

在你的照片目录中试试这个。

RewriteEngine On

# neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home$ home.php [QSA,L]

【讨论】:

    【解决方案2】:

    首先,确保您的 .htaccess 文件位于项目的基本目录中。接下来,关注these htaccess rules 设置您的重定向。

    您可能正在寻找的 .htaccess 解决方案是:

    RewriteEngine On
    
    #Neither a file nor a directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^photo/home$ photo/home.php [QSA,L]
    

    【讨论】:

      【解决方案3】:

      当我将.htaccess 代码放在根.htaccess 中时,我遇到了这个问题。当我在与 public_html 文件夹相同级别的子域文件夹中创建一个新的.htaccess 并用所需的 RewriteRule 填充它时,它可以工作

      【讨论】:

        猜你喜欢
        • 2014-04-16
        • 1970-01-01
        • 1970-01-01
        • 2020-07-01
        • 2017-03-21
        • 2010-10-16
        • 1970-01-01
        • 2013-05-22
        • 2018-04-19
        相关资源
        最近更新 更多