1

I've got the following structure

www/
  .htaccess
  /website1
  /website2
  /uploads/foo.pdf
  /websiteWP
    .htaccess

.htacces in root (www/.htaccess)

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?foo.com$

RewriteCond %{REQUEST_URI} !^/website1/
RewriteCond %{REQUEST_URI} !^/website2/
RewriteCond %{REQUEST_URI} !^/uploads/
RewriteCond %{REQUEST_URI} !^/websiteWP/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /websiteWP/$1

RewriteCond %{HTTP_HOST} ^(www.)?foo.com$
RewriteRule ^(/)?$ websiteWP/index.php [L] 
</IfModule>

.htacces in wordpress installation (www/websiteWP/.htaccess)

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

Inside the Wordpress, clicking the link https://www.foo.com/uploads/some-pdf.pdf will result in an infinite loading page, trying to load content (this reaction is due to the theme, I supose others can have a 404), or sometimes combining half wordpress with half "embeded" remote page.

But going to the pdf from outside the website (pasting in the search box) will work.

Note:

Wordpress URL: https://www.foo.com/websiteWP

Website URL: https://www.foo.com

Can't find the failure of the .htaccess.

Already checked all available threads in stackoverflow and wordpress stackexchange.

  • In your example link you've used foo.es, but in other places you've used foo.com - is that intentional? Or should it all be foo.com? Do you have multiple domains? "But going to the pdf from outside the website will work" - there should be no difference - if the link is the same then the result should be the same, since they both result in the same request. – MrWhite Nov 14 '18 at 23:48
  • @MrWhite mb doing the dummy data, all is foo.com – Qu4k3 Nov 14 '18 at 23:49
  • @MrWhite one is a link inside wordpess clicked through the website, the other one is an external link. But yes, basically the same request. – Qu4k3 Nov 14 '18 at 23:52
  • ...but with a different result? – MrWhite Nov 15 '18 at 11:30
  • Yes, I started to think that is more likely to be a theme problem than a missconfirugation. I think there is javascript that make transitions between page and page that provoque the page to not load a page and it tries to load the pdf/external website inside the content of the current site. – Qu4k3 Nov 15 '18 at 11:35
0

It's not clear from the .htaccess files you've posted why you can't access files/folders outside of your WordPress installation (inside the /websiteWP subdirectory). In fact, you shouldn't need to add specific exceptions in order to access physical files, since these directives shouldn't apply to physical files.

However, your .htaccess files are misconfigured...

If the WordPress installation is in /websiteWP directory then the /websiteWP/.htaccess file (in the route of your WordPress installation) is incorrect, as it is routing all requests to /index.php - that's the index.php file in the document root (which I assume is the parent directory), not the WordPress front-controller which should be in the same directory, ie. /websiteWP/index.php).

However, I assume /index.php (in the document root) doesn't exist (otherwise your WordPress site won't work). The .htaccess directives in the root .htaccess file are then rewriting the request back to the /websiteWP/index.php WordPress front-controller! This is extra work and unnecessary.

You should change the /websiteWP/.htaccess file to read:

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

Note I have removed the RewriteBase directive and removed the slash prefix on the RewriteRule susbstitution, changing /index.php (root-relative) to index.php (relative).

Then, the root .htaccess file is not required at all.

  • I'll try this solution, wordpress's guide says to put a htaccess in root folder guide, that make sense cause I need to redirect / to /new/ otherwise a forbidden access will apear since root folder has no index.php But maybe root's htaccess has redundant information. – Qu4k3 Nov 16 '18 at 11:40
  • Sometimes I got an Cannot parse upstream response error when I visit a page in wordpress (foo.com/some-page) image – Qu4k3 Nov 16 '18 at 11:56
  • That "guide" is regarding moving an installation that was in the root to a subdirectory, without necessarily changing the URL (ie. without exposing the subdirectory). Or having an installation in a subdirectory, but making it look as if it is in the root? Is that what you have done? However, you would still need to modify the subdirectory .htaccess file to avoid this "double" rewrite. The root .htaccess file doesn't actually "redirect" anything, it "rewrites" the URL. Maybe you do need a "redirect"? Should /websiteWP be part of the URL? – MrWhite Nov 16 '18 at 13:52
  • As it stands it looks like your WordPress pages maybe accessible from 2 URLs, both with and without the /websiteWP subdirectory. I'm not sure what "Cannot parse upstream response" would relate to? You say you only get that error "sometimes"? – MrWhite Nov 16 '18 at 13:54
  • I'm sorry that I'm confusing you even more. having an installation in a subdirectory, but making it look as if it is in the root that's it. There is no website on root, all websites are in their folders, but wanted to make /websiteWP/ the main one, without showing the folder. – Qu4k3 Nov 16 '18 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.