gpt4 book ai didi

php - 如何在 .htaccess 中编写 rewriteCond 以排除子目录及其子目录

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:43:08 27 4
gpt4 key购买 nike

我有以下问题。我在子目录中有一个网站和一个博客。他们两个都是php。我在根文件夹中有一个 .htaccess 文件,在博客文件夹中有另一个文件。我认为不相关,但博客脚本是 wordpress。

我在根 .htaccess 中添加了一个条件来跳过对博客的请求,

rewriteCond %{REQUEST_URI} !^/blog.*

这是它的样子。我删除了文件的其余部分:

Options +FollowSymlinks -MultiViews RewriteEngine on

RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/

// my added line RewriteCond %{REQUEST_URI} !^/blog.*


RewriteCond %{HTTP_HOST} !^www\. RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^(all)/([^/]+)/?$ story.php?title=$2 [L] RewriteRule ^(all)/?$ ?category=$1 [L]

RewriteRule ^/?$ index.php [L] RewriteRule ^advanced-search/?$ advancedsearch.php [L] ...

我遇到的问题与博客请求有关。例如,有时如果我尝试打开一个 url 它工作正常,有时会打开主页(根页面而不是博客)。这似乎很奇怪。我觉得跟楼主有关。当主机忙时,找不到我请求的博客页面,因此请求将转到根 .htaccess。

我有两个问题:

  • 如何编写规则以及在何处编写放置它以排除所有请求/blog 被 root 重写.htaccess?博客请求可能看起来像 http://test.com/blog,http://test.com/blog/,http://test.com/blog/title,http://test.com/blog/title/,http://test.com/blog/category/title
  • 有人知道会发生什么吗?为什么当我打开博客页面时它会打开主页根页面,而如果我刷新页面它会转到博文页面?

最佳答案

查看 mod_rewrite documentation ,特别是 RewriteCond 中的 -d 标志。

应该是这样的:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule HERE

关于php - 如何在 .htaccess 中编写 rewriteCond 以排除子目录及其子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1257578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com