mod_rewrite的:被重定向到根文件夹;我希望它留在子文件夹 [英] mod_rewrite: Being redirected to root folder; I want it to stay in sub-folder
问题描述
我有一个Zend框架的网站在这个DIR /var/www/example.com /
,把WP博客在此目录 / VAR /www/example.com/public/blog /
以下是重要的文件...
/var/www/example.com/public/.htaccess
包括:
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME -s [OR]
的RewriteCond%{} REQUEST_FILENAME -l [OR]
的RewriteCond%{} REQUEST_FILENAME -d
。重写规则^ * $ - [NC,L]
重写规则^博客 - [NC,L] #Just加入这一行,这是previous不存在
重写规则^ * $的index.php [NC,L]
然后我的.htaccess
在 /博客/
文件夹是这样的:
#BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /博客/
重写规则^指数\ .PHP $ - [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。 /blog/index.php [L]
< / IfModule>
#结束字preSS
点击周围的Zend的网站能正常工作。在进入/博客/子文件夹中加载WP博客就好了。但是,当我点击的博客任何职位,它就会被重定向到ZF的应用程序,并且不留在字preSS。
最终的结果,我追,是保持两个独立的,但要确保他们都改写的index.php所以它不是在URL中呈现。
我没有与htaccess的好经验,所以我不知道发生了什么。这是我的虚拟主机只为好措施。
<虚拟主机*:80>
的ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot的/var/www/example.com/public
服务器名example.com
错误日志记录/ example.local-error.log中
的CustomLog日志/ example.local-access.log的共同
<目录/var/www/example.com/public>
选择指标的FollowSymLinks
设置AllowOverride所有
订购允许,拒绝
允许所有
< /目录>
<位置/>
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
!重写规则\(JS | ICO | GIF | JPG | PNG | CSS)$的index.php
< /地点>
SETENV APPLICATION_ENV发展
< /虚拟主机>
注意我辗转于 /公/
文件夹,因为在虚拟主机重写规则的测试,但的.htaccess我的问题仍然存在
请求和放大器;响应URL是相同的,因为它们显示在浏览器:
HTTP://example.local/blog/my-test-blog-post/
不过,浏览器呈现来自采埃孚的错误,表示这是导演的公共/ index.php文件
文件,而不是预期的公共/博客/ index.php文件
文件。我还使用了Netbeans的&放大器; XDebug的步骤通过code。我把两个的index.php文件的第一行设置一个断点,然后点击博客文章的链接时,它会立即加载ZF的index.php,而不是/blog/index.php
如果我使用像 环视谷歌,它告诉我在 我也将增加mod_rewrite已工作,因为我可以通过ZF的应用程序就好了点击。 最后要注意,这个永久适用于WP: 不过,我想用这个没有索引文件:
mod_rewrite的日志: HTTP的URL看起来。但是当我使用可湿性粉剂管理员自定义永久链接像
的http://example.local/blog/my-test-blog-post/
尝试路由到ZF <。 / P>
/博客/
文件夹是不正确的htaccess的。 有FollowSymLinks
&放大器; 的AllowOverride全部
都设置。我只是无法得到它的权利...
HTTP://word$p$pss.org/support /主题/自定义永久链接 - 不工作-1 /index.php/%post_id%/%postname%/
/%的post_id%/%postname%/
1(2)初始重写引擎请求的URI /博客/ 698 /测试博客岗位/
(1)通过/博客/ 698 /测试博客岗位/
(3)[perdir /]添加路径信息后缀:D:/网络/例子/公/博客/ 698 - &GT; D:/网络/例子/公/博客/ 698 /测试博客岗位/
(3)[perdir /]应用模式。\(JS | ICO | GIF | JPG | PNG | CSS)$'到URID:/网络/例子/公/博客/ 698 /测试博客岗位/
(4)[perdir /]的RewriteCond:输入='D:/网络/例子/公/博客/ 698模式= - =&GT;'F!匹配
'! - D'(4)[perdir /]的RewriteCond:输入='D /网络/例子/公/博客/ 698模式= =&GT;匹配
(2)[perdir /]改写D:/网络/例子/公/博客/ 698 /测试博客员额/ - &GT; 的index.php
(2)[perdir /]试图取代preFIX /带/
(5)条匹配preFIX:的index.php - &GT;的index.php
(4)增加SUBST preFIX:index.php文件 - &GT;的index.php
(1)[perdir /]内部重定向用的index.php [内部重定向]
(2)初始重写引擎与请求的URI的index.php
(1)通过的index.php
(3)[perdir /]应用模式。\(JS | ICO | GIF | JPG | PNG | CSS)$'到URID:/www/example/public/index.php
(4)[perdir /]的RewriteCond:输入='D:/www/example/public/index.php'模式= - =&GT;'F!不匹配
(1)[perdir /]通过D:/www/example/public/index.php
另一个mod_rewrite的日志在尝试贾森·迪恩的建议(没有工作)
与请求的URI /博客(2)初始重写引擎/ 698 /测试博客岗位/
(1)通过/博客/ 698 /测试博客岗位/
(3)[perdir /]添加路径信息后缀:D:/网络/例子/公/博客/ 698 - &GT; D:/网络/例子/公/博客/ 698 /测试博客岗位/
(3)[perdir /]应用模式。\(JS | ICO | GIF | JPG | PNG | CSS)$'到URID:/网络/例子/公/博客/ 698 /测试博客岗位/
(4)[perdir /]的RewriteCond:输入='D:/网络/例子/公/博客/ 698模式= - =&GT;'F!匹配
'! - D'(4)[perdir /]的RewriteCond:输入='D /网络/例子/公/博客/ 698模式= =&GT;匹配
(2)[perdir /]改写D:/网络/例子/公/博客/ 698 /测试博客员额/ - &GT; 的index.php
(2)[perdir /]试图取代preFIX /带/
(5)条匹配preFIX:的index.php - &GT;的index.php
(4)增加SUBST preFIX:index.php文件 - &GT;的index.php
(1)[perdir /]内部重定向用的index.php [内部重定向]
(2)初始重写引擎与请求的URI的index.php
(1)通过的index.php
(3)[perdir /]应用模式。\(JS | ICO | GIF | JPG | PNG | CSS)$'到URID:/www/example/public/index.php
(4)[perdir /]的RewriteCond:输入='D:/www/example/public/index.php'模式= - =&GT;'F!不匹配
(1)[perdir /]通过D:/www/example/public/index.php
尝试添加:
的RewriteCond%{REQUEST_URI}!^ /博客
要你的第一个的.htaccess
我认为这是拦截到您的博客子文件夹中的任何请求。
I have a Zend Framework site in this dir /var/www/example.com/
and put the WP blog in this dir /var/www/example.com/public/blog/
The following are the important files...
/var/www/example.com/public/.htaccess
contains:
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]
Then my .htaccess
in the /blog/
folder is this:
# 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
Clicking around the zend site works fine. Going into the /blog/ subfolder loads the WP blog just fine. But when I click on any post in the blog, it gets redirected to the ZF app, and doesn't stay within wordpress.
The end result I am chasing is to keep the two separate, yet make sure both of them rewrite the index.php so it isn't rendered in the URL.
I don't have good experience with htaccess so I am not sure what's happening. Here is my VHost just for good measure.
<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>
NOTE I removed the .htaccess in the /public/
folder for testing because of the Rewrite rule in the VHost, but my problem remains.
The request & response URLs are the same as they are shown in the browser:
http://example.local/blog/my-test-blog-post/
HOWEVER, the browser renders an error from ZF, indicating it was directed to the public/index.php
file instead of the intended public/blog/index.php
file. I also used Netbeans & XDebug to step through the code. I put a breakpoint on the first line of both index.php files, and when clicking a blog post link, it immediately loads the ZF index.php, not the /blog/index.php
It appears if I use a URL like http://example.local/blog/?p=695
it works and is not routed to the ZF app. but when I use custom permalinks in wp-admin like http://example.local/blog/my-test-blog-post/
it tries to route to ZF.
From looking around google, it tells me the htaccess in the /blog/
folder is incorrect. Options FollowSymLinks
& AllowOverride All
are both set. I just can't get it right...
http://wordpress.org/support/topic/custom-permalinks-not-working-1
I will also add that mod_rewrite IS working because I can click through the ZF app just fine.
As a final note, this permalink works on WP:
/index.php/%post_id%/%postname%/
But I want to use this without the index file:
/%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
Another mod_rewrite log After trying Jason Dean's suggestion (didn't work)
(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
Try adding:
RewriteCond %{REQUEST_URI} !^/blog
To your first .htaccess
I think that it is intercepting any requests to your blog subfolder.
这篇关于mod_rewrite的:被重定向到根文件夹;我希望它留在子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!