Site in subfolder – all pages work except home

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x