【发布时间】:2009-10-12 18:28:32
【问题描述】:
我正在使用 Wordpress 并拥有以下 pemalink /%category%/%postname%。
这为我提供了用户友好的 URL,例如 http://www.example.com/something/。
有了这个永久链接,我将无法直接访问 php 文件,例如http://www.example.com/something/myfile.php.
我需要编写一个允许我访问 /include/myfile.php 的重写规则。 有人可以帮我吗? :)
这是我当前的 .htaccess 文件:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myblogdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblogdirectory/index.php [L]
</IfModule>
# END WordPress
更新
好的,我搞定了。
我从一开始就做错了。我使用的是“虚拟”路径而不是物理路径。
我必须使用/wp-content/themes/mytheme/include/myfile.php,而不是/mysite/includes/myfile.php
我可能还添加了 RewriteCond %{REQUEST_URI} !myfile.php,这会将 myfile.php 从重写规则中排除。不过我还没有测试过。
【问题讨论】:
-
尝试使用 mod_rewrite 的日志进行一些调试(参见 RewriteLogLevel)。
-
完成。更新了上面的文字
-
根据日志,
/include不是目录。还是这样? -
/include/ 是一个目录,是的。我发现了问题(上面的答案)。我也在四处挖掘之后发现我可能已经使用 RewriteCond %{REQUEST_URI} !myfile.php 将该文件从重写规则中排除。
标签: wordpress .htaccess mod-rewrite permalinks