【问题标题】:Page not found when rewriting URL through .htaccess通过 .htaccess 重写 URL 时找不到页面
【发布时间】:2015-05-03 23:53:19
【问题描述】:

我在尝试为网站设置 .htaccess 时遇到问题。

当页面访问此文件夹时,我试图从 URL 中删除文件夹。我设法使用这篇文章How can I remove this directory/folder from url with htaccess rewrite? 成功地从路径中删除了文件夹,但是当我加载页面时,没有正确加载 css、javascript 或其他资源。

当我尝试从 url 访问资源时,它显示“在此服务器上找不到请求的 URL /modules/content/styles/default.css。”

Modules 是我在访问页面时尝试删除的文件夹,但似乎当我将代码添加到 htaccess 时,它会将“模块”添加到所有路径。

我的文件结构是这样的

我在根目录中有一个 .htaccess 文件,代码如下:

RewriteEngine on
RewriteRule !^/?modules modules%{REQUEST_URI} [L,NC]

我在模块文件夹中也有一个代码:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+modules([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]

我尝试了多种解决方案,但都以“找不到页面”结尾,这是我得到的最接近的解决方案,但现在我遇到了资源问题。

任何帮助都会很棒!

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    你需要在 root .htaccess 中更改此规则:

    RewriteEngine on
    
    # If the request is not for a valid directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # If the request is not for a valid file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule !^modules/ modules%{REQUEST_URI} [L,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多