【发布时间】:2009-08-10 22:27:19
【问题描述】:
我有以下问题。我在子目录中有一个网站和一个博客。它们都是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 被根重写 .ht 访问?博客请求可能 看起来像 http://test.com/blog, http://test.com/blog/, http://test.com/blog/title, http://test.com/blog/title/, http://test.com/blog/category/title
- 有人知道会发生什么吗?为什么当我打开博客页面时,它会打开主页根页面,如果我刷新页面,它会转到博客文章页面?
【问题讨论】:
-
能否请您格式化代码,使其更“可读”(= 正确位置的换行符)?谢谢!
标签: php .htaccess redirect mod-rewrite