通过 .htaccess 重写 URL 时找不到页面
Page not found when rewriting URL through .htaccess
我在尝试为网站设置 .htaccess 时遇到问题。
当页面访问此文件夹时,我试图从 URL 中删除一个文件夹。我成功地使用此 post How can I remove this directory/folder from url with htaccess rewrite? 从路径中删除了文件夹,但是当我加载页面时, css、javascript 或其他的 none资源已正确加载。
当我尝试从 url 访问资源时,它显示 'The requested URL /modules/content/styles/default.css was not found on this server.'
Modules 是我在访问页面时试图删除的文件夹,但是当我将代码添加到 htaccess 时,它似乎正在向所有路径添加 "modules"。
我的文件结构是这样的
我在根目录中有一个 .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]
我尝试了多种解决方案,但都以 "Page not found" 结尾,这是我得到的最接近的解决方案,但现在我遇到了资源问题。
任何帮助都会很棒!
您需要在 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]
我在尝试为网站设置 .htaccess 时遇到问题。
当页面访问此文件夹时,我试图从 URL 中删除一个文件夹。我成功地使用此 post How can I remove this directory/folder from url with htaccess rewrite? 从路径中删除了文件夹,但是当我加载页面时, css、javascript 或其他的 none资源已正确加载。
当我尝试从 url 访问资源时,它显示 'The requested URL /modules/content/styles/default.css was not found on this server.'
Modules 是我在访问页面时试图删除的文件夹,但是当我将代码添加到 htaccess 时,它似乎正在向所有路径添加 "modules"。
我的文件结构是这样的
我在根目录中有一个 .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]
我尝试了多种解决方案,但都以 "Page not found" 结尾,这是我得到的最接近的解决方案,但现在我遇到了资源问题。
任何帮助都会很棒!
您需要在 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]