【问题标题】:Need help with .htaccess ReWrite rules在 .htaccess 重写规则方面需要帮助
【发布时间】: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


【解决方案1】:

嗯,你的重写规则看起来不错。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

意味着如果 %{REQUEST_FILENAME] 是一个物理文件或目录,则 /blog/index.php 将不会被服务。

更多信息here

您确定您使用的是正确的文件路径吗?

您要请求的文件应该位于/blog/include/myfile.php。

检查您的 error.log 中是否有 apache 的任何相关消息。

【讨论】:

  • 但不是说“这些规则的基础是 /myblogdirectory/”。如果请求whatever.php 文件,请将请求转发到/myblogdirectory/index.php" ?(我已将代码更新为。)
  • 附言。这是一篇关于理解 Wordpress 永久链接的好文章:homebizpal.com/blogging/wordpress/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-29
  • 1970-01-01
  • 2011-04-04
  • 2011-09-28
  • 1970-01-01
  • 2013-03-15
相关资源
最近更新 更多