【问题标题】:.htaccess rewrite to uri where filename exists but extension omitted.htaccess 重写为存在文件名但省略扩展名的 uri
【发布时间】:2021-07-24 22:58:28
【问题描述】:

我的 .htaccess 遇到了一个奇怪的问题,它无法将它传递给 index.php。使用我当前的重写规则,如果我转到 mysite.com/abc123,它会正确重定向到 index.php,将 /abc123 传递给 index.php 处理的查询字符串。

但是,如果我访问 mysite.com/test,我会看到 apache Not Found 错误页面。我希望这会转到 index.php 并作为查询字符串通过测试。

如果我访问 mysite.com/test.php,它会按预期加载该文件。

我的文件结构如下:

/
|- index.php
|- test.php
|- .htaccess

这是我当前的 .htaccess 文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /([a-z\-A-Z]+)
RewriteRule .* index.php?/$0 [L,QSA]

</IfModule>

# END WordPress

<FilesMatch "\.(html|css|js|gif|jpg|jpeg|png|ico|swf)$">
    Header set Cache-Control "max-age=259200, proxy-revalidate"
</FilesMatch>  

【问题讨论】:

标签: apache .htaccess url mod-rewrite url-rewriting


【解决方案1】:

Options 中删除MultiViews

或者如果你找不到 Options 指令的位置,你可以添加这个:

Options -MultiViews

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2014-01-12
    相关资源
    最近更新 更多