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

5 php .htaccess mod-rewrite redirect

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

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

rewriteCond %{REQUEST_URI} !^/blog.*
Run Code Online (Sandbox Code Playgroud)

这是它的外观.我删除了文件的其余部分:

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] ...
Run Code Online (Sandbox Code Playgroud)

我遇到的问题与博客请求有关.例如,有时如果我尝试打开网址就可以正常工作,有时会打开主页(根页面而不是博客).这看起来很奇怪.我认为这与主持人有关.当主机忙于我找不到的博客页面时,请求将转到root .htaccess.

我有两个问题:

  • 如何写一个规则以及在哪里放置它以排除由.htaccess重写/ blog的所有请求?博客请求可能看起来像http://test.com/blog,http://test.com/blog/,http://test.com/blog/title,http://test.com/blog/title /,http://test.com/blog/category/title
  • 有谁知道会发生什么?为什么当我打开博客页面打开主页根页时,如果我刷新页面,它会进入博客帖子页面?

Ali*_*xel 3

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

它应该是这样的:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule HERE
Run Code Online (Sandbox Code Playgroud)