【问题标题】:htaccess - RewriteRules declared causing 404 errorshtaccess - RewriteRules 声明导致 404 错误
【发布时间】:2021-10-04 10:44:56
【问题描述】:

不知道为什么我的 .htaccess 文件没有做它应该做的关于 mod_rewrite 的事情。

mod_rewrite 已启用,并且我相信目录路径具有正确的指令。

<Directory /var/www/html/test>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

在 ubuntu 20.04 上运行 apache2

这是我当前的 .htaccess 文件:

RewriteEngine on
RewriteCond %{THE_REQUEST} /test/_plugin/accounts/ [NC]
RewriteRule ^test/_plugin/accounts/(.*)$ /test/accounts/$1 [L,R]
RewriteRule ^test/accounts/(.*)$ /test/_plugin/accounts/$1 [L]

我在这里想要完成的是:

  • 保留/test/_plugin/accounts/ 的内容并显示该内容以将URL 重写为/test/accounts/,其中/test/accounts/ 目录实际上并不存在。

对此的任何帮助将不胜感激

【问题讨论】:

  • 究竟是什么不工作?
  • 404 Not Found...我猜是因为/test/accounts/ 实际上并不存在。有没有办法将内容从/test/_plugin/accounts/ 复制到/test/accounts//test/accounts/ 实际上存在重写?
  • 这个 htaccess 文件位于哪个文件夹?
  • 它位于/test/文件夹中

标签: .htaccess mod-rewrite url-rewriting apache2 ubuntu-20.04


【解决方案1】:

我相信我现在已经弄清楚了。我去掉了Indexes 指令,这似乎使事情顺利进行。

<Directory /var/www/html/test>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

并稍微修改了 .htaccess:

RewriteCond %{THE_REQUEST} /test/_plugin/accounts/ [NC]
RewriteRule ^_plugin/accounts/(.*)$ /test/accounts/$1 [L,R]
RewriteRule ^accounts/(.*)$ /test/_plugin/accounts/$1 [L]

【讨论】:

    猜你喜欢
    • 2022-09-22
    • 1970-01-01
    • 2015-05-24
    • 2021-09-02
    • 1970-01-01
    • 2019-12-10
    • 2022-12-10
    • 2012-11-09
    • 1970-01-01
    相关资源
    最近更新 更多