Mod_rewrite在htaccess重定向,而不是重写,不能100%工作



我需要静态页面来接管我正在使用的大部分wordpress站点。为了保存静态页面,我已经创建了一个/static目录,但是我还需要保持现有博客的可见性。我有以下代码在我的.htaccess文件:

RewriteEngine On
RewriteRule ^blog index.php [L]
RewriteRule ^20* index.php [L]
RewriteRule ^$ static [L]

mydomain.com/blogmydomain.com/2014/01/blog-post都工作,但如果我试图去mydomain.com的URL是重定向mydomain.com/static,这不是我想要完成的。

此外,尝试访问任何其他页面,如mydomain.com/about.php抛出404错误,这使我认为我的重写是完全错误的。基本上,我希望除了博客页面和博客文章之外的所有请求都被重写到/static

中的文件中。

您需要在目录的末尾加上一个尾斜杠,否则mod_dir和DirectorySlash会将浏览器重定向到带有尾斜杠的URL。第三条规则是

RewriteRule ^$ static/ [L]

最新更新