.htaccesss RewriteCond %{REQUEST_FILENAME} !-d does not work

admin

Administrator
Staff member
I want to install WordPress in subdirectory and remove index.php in permalinks.
The server is IIS 6.0, support rewrite.
My webserver has the following directories:

<blockquote>
webroot<br>
--wp [wordpress folder]
</blockquote>

<strong>webroot/.htaccess</strong>

Code:
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/

<strong>webroot/wp/.htaccess</strong>

Code:
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #3

It works when I visit <em>a.luckyet.com</em> and <em>a.luckyet.com/hello-world.html</em>
But it does not work when I visit <em>a.luckyet.com/wp-login.php</em> or <em>a.luckyet.com/wp-admin</em>

The #3 works fine, but #1 and #2 can not work properly. Then I saw <a href="https://stackoverflow.com/questions/6930519/write-an-htaccess-file-without-request-filename">here</a> and change the content of <strong>webroot/wp/.htaccess</strong> to:

Code:
RewriteEngine on 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

It still does not take effect. Can anyone help me? Thanks in advance!

<strong>Update:</strong>

ISAPI_Rewrite version is 3.0.

All code in <strong>webroot/.htaccess</strong>:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/

All code in <strong>webroot/wp/.htaccess</strong>:

Code:
RewriteEngine on 
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule wp-(.*) wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule (.*) index.php/$1 [L]

Wordpress permalink is:

Code:
/%postname%.html

Thus, Wordpress can work fine when visit <a href="http://a.luckyet.com/" rel="nofollow noreferrer">http://a.luckyet.com/</a> or <a href="http://a.luckyet.com/hello-world.html" rel="nofollow noreferrer">http://a.luckyet.com/hello-world.html</a>

<strong>Question:</strong>

If there is a real file like a.html in <em>webroot/wp/</em>, like <em>webroot/wp/a.html</em>, wordpress 404 error will be reported when visit <em><a href="http://a.luckyet.com/a.html" rel="nofollow noreferrer">http://a.luckyet.com/a.html</a></em>, . How can I fixed this?