我在这个目录/var/www/example.com/
中有一个Zend Framework网站,并将WP博客放在这个目录/var/www/example.com/public/blog/
以下是重要文件......
/var/www/example.com/public/.htaccess
包含:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^blog - [NC,L] #Just added this line, it was previous not there
RewriteRule ^.*$ index.php [NC,L]
然后.htaccess
文件夹中的/blog/
就是这样:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
点击zend网站可以正常工作。进入/ blog /子文件夹加载WP博客就好了。但是,当我点击博客中的任何帖子时,它会被重定向到ZF应用程序,并且不会保留在wordpress中。
我追逐的最终结果是保持两者分开,但要确保它们都重写index.php,以便它不会在URL中呈现。
我对htaccess没有很好的经验,所以我不确定发生了什么。这是我的VHost只是为了好的措施。
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www/example.com/public"
ServerName example.com
ErrorLog "logs/example.local-error.log"
CustomLog "logs/example.local-access.log" common
<Directory "/var/www/example.com/public" >
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Location />
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
</Location>
SetEnv APPLICATION_ENV development
</VirtualHost>
注意由于VHost中的重写规则,我删除了/public/
文件夹中的.htaccess进行测试,但我的问题仍然存在。
请求&amp;响应URL与浏览器中显示的相同:
http://example.local/blog/my-test-blog-post/
但是,浏览器从ZF呈现错误,表明它已定向到public/index.php
文件而不是预期的public/blog/index.php
文件。我还使用过Netbeans&amp; XDebug逐步执行代码。我在两个index.php文件的第一行放了一个断点,当点击博客帖子链接时,它会立即加载ZF index.php,而不是/blog/index.php
如果我使用像http://example.local/blog/?p=695
这样的网址,它就可以使用并且不会路由到ZF应用。但是当我在像http://example.local/blog/my-test-blog-post/
这样的wp-admin中使用自定义永久链接时,它会尝试路由到ZF。
从浏览谷歌,它告诉我/blog/
文件夹中的htaccess是不正确的。 Options FollowSymLinks
&amp; AllowOverride All
都已设置。我只是无法做对......
http://wordpress.org/support/topic/custom-permalinks-not-working-1
我还要补充说mod_rewrite IS工作正常,因为我可以点击ZF应用程序就好了。
最后一点,这个永久链接适用于WP:
/index.php/%post_id%/%postname%/
但我想在没有索引文件的情况下使用它:
/%post_id%/%postname%/
mod_rewrite log:
1(2) init rewrite engine with requested uri /blog/698/test-blog-post/
(1) pass through /blog/698/test-blog-post/
(3) [perdir /] add path info postfix: D:/www/example/public/blog/698 -> D:/www/example/public/blog/698/test-blog-post/
(3) [perdir /] applying pattern '\.(js|ico|gif|jpg|png|css)$' to uri 'D:/www/example/public/blog/698/test-blog-post/'
(4) [perdir /] RewriteCond: input='D:/www/example/public/blog/698' pattern='!-f' => matched
(4) [perdir /] RewriteCond: input='D:/www/example/public/blog/698' pattern='!-d' => matched
(2) [perdir /] rewrite 'D:/www/example/public/blog/698/test-blog-post/' -> '/index.php'
(2) [perdir /] trying to replace prefix / with /
(5) strip matching prefix: /index.php -> index.php
(4) add subst prefix: index.php -> /index.php
(1) [perdir /] internal redirect with /index.php [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /index.php
(1) pass through /index.php
(3) [perdir /] applying pattern '\.(js|ico|gif|jpg|png|css)$' to uri 'D:/www/example/public/index.php'
(4) [perdir /] RewriteCond: input='D:/www/example/public/index.php' pattern='!-f' => not-matched
(1) [perdir /] pass through D:/www/example/public/index.php
另一个mod_rewrite日志在尝试了Jason Dean的建议后(没有用)
(2) init rewrite engine with requested uri /blog/698/test-blog-post/
(1) pass through /blog/698/test-blog-post/
(3) [perdir /] add path info postfix: D:/www/example/public/blog/698 -> D:/www/example/public/blog/698/test-blog-post/
(3) [perdir /] applying pattern '\.(js|ico|gif|jpg|png|css)$' to uri 'D:/www/example/public/blog/698/test-blog-post/'
(4) [perdir /] RewriteCond: input='D:/www/example/public/blog/698' pattern='!-f' => matched
(4) [perdir /] RewriteCond: input='D:/www/example/public/blog/698' pattern='!-d' => matched
(2) [perdir /] rewrite 'D:/www/example/public/blog/698/test-blog-post/' -> '/index.php'
(2) [perdir /] trying to replace prefix / with /
(5) strip matching prefix: /index.php -> index.php
(4) add subst prefix: index.php -> /index.php
(1) [perdir /] internal redirect with /index.php [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /index.php
(1) pass through /index.php
(3) [perdir /] applying pattern '\.(js|ico|gif|jpg|png|css)$' to uri 'D:/www/example/public/index.php'
(4) [perdir /] RewriteCond: input='D:/www/example/public/index.php' pattern='!-f' => not-matched
(1) [perdir /] pass through D:/www/example/public/index.php
答案 0 :(得分:1)
尝试添加:
RewriteCond %{REQUEST_URI} !^/blog
到你的第一个.htaccess
我认为它拦截了对您的博客子文件夹的任何请求。