admin管理员组

文章数量:1125975

Our WordPress site is in a subfolder /subwp/, and all pages except the home page work. This is the root folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subwp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subwp/index.php [L]
</IfModule>

When visiting the homepage (e.g. /) I get the hosting providers default site ('this domain is hosted by xyz'). All other slugged pages work perfectly.

Just to make sure that the hosting provider is not somehow auto redirecting requests to /, I created a file named index.php with just 'blah' in it, to see if it would work then, and then if I visit , I see the text 'blah' (and also all other pages display blah now :))

I'm kinda stuck. Any ideas?

Our WordPress site is in a subfolder /subwp/, and all pages except the home page work. This is the root folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subwp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subwp/index.php [L]
</IfModule>

When visiting the homepage (e.g. http://example.com/) I get the hosting providers default site ('this domain is hosted by xyz'). All other slugged pages work perfectly.

Just to make sure that the hosting provider is not somehow auto redirecting requests to /, I created a file named index.php with just 'blah' in it, to see if it would work then, and then if I visit http://example.com, I see the text 'blah' (and also all other pages display blah now :))

I'm kinda stuck. Any ideas?

Share Improve this question edited Dec 1, 2020 at 16:50 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Dec 1, 2020 at 15:51 Marcelnl1Marcelnl1 132 bronze badges 1
  • Do you have another .htaccess file in the WordPress subdirectory, or are you doing everything from the root .htaccess file? – MrWhite Commented Dec 1, 2020 at 16:51
Add a comment  | 

2 Answers 2

Reset to default 0

Because when you request the document root, the rule in .htaccess does not match and the request is not rewritten to the subdirectory. So the request falls through and whatever is the default response for the document root is served (eg. /index.php if it exists).

You need to add another directive to rewrite the homepage only.

(The first RewriteRule directive is not correct either.)

For example:

RewriteEngine On
RewriteBase /subwp/

RewriteRule ^[^/]+/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

# Special case - rewrite requests for the homepage (which is also a directory) 
RewriteRule ^$ index.php [L]

Since you are using RewriteBase you can remove the /subwp/ prefix on the RewriteRule substitution strings (that's the whole point of using RewriteBase).

An alternative... This was driving up the wall and the provided solution was not working. Turned out my browser had cached a 301 error with forwarding to the WordPress folder version of the URL. I cleared the cache and my problem was fixed.

本文标签: htaccessSite in subfolderall pages work except home