开发者

mod_rewrite: Being redirected to root folder; I want it to stay in sub-folder

开发者 https://www.devze.com 2023-04-06 02:33 出处:网络
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/

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
Rewr开发者_如何学CiteRule . /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.

0

精彩评论

暂无评论...
验证码 换一张
取 消