2

I have three sites running in a shared hosting (Bluehost) with a dedicated IP address. The description is as follow:

  • example.com => this is the main site and domain, is a WP
  • example.net => this is an add-on domain (don't know if you're familiar with the term) and is running another WP site
  • subsite.example.net => this is a standalone PHP application

Each WP has it's own .htacess file which looks like:

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

With this .htaccess file both WP sites works fine but the standalone application doesn't. If I remove the .htaccess file then is the opposite, the standalone application works but the WP sites doesn't.

Can any help me to find a solution to this issue?

Update

I am playing with the following config for the .htaccess file for the standalone PHP application:

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

    # Add Caching.
    <FilesMatch ".(ico|jpg|jpeg|png|gif|js|css|swf)$">
        Header set Cache-Control "max-age=10800"
    </FilesMatch>

    # Prevent viewing of htaccess file.
    <Files .htaccess>
        order allow,deny
        deny from all
    </Files>

    # Prevent directory listings
    Options All -Indexes

    # Compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

but is not working since I am kick out of the application as soon as I click on any link.

The standalone site lives at /public_html/plataforma while the WP lives at /public_html. Why I am doing wrong at this point?

ReynierPM
  • 700
  • 5
  • 14
  • 28
  • Are you using VirtualHosts to separate the sites, or how is that done? With a proper setup, each .htaccess would only affect the directory it's in, and each domain and subdomain would be in its own directory so you should be able to remove the .htaccess for the PHP application without affecting the Wordpress sites. – Jenny D Nov 09 '16 at 08:55
  • @JennyD I am not sure at all how this is being handle by hosting personal and them aren't so good doing support. I have tried to fix the issue like five times before came here and ask for help and they keep saying the problem is coming from the app which isn't. I am just figure it out the problem is the `.htaccess` file. – ReynierPM Nov 09 '16 at 10:54

2 Answers2

2

create .htaccess file for your standalone PHP application that will redirect your code to subsite.example.net

Jenny D
  • 27,358
  • 21
  • 74
  • 110
Sukhjinder Singh
  • 1,944
  • 2
  • 8
  • 17
2

What is important is the underlying file/directory structure. If these 3 sites are essentially on the same account - the same parent directory - then each site is probably in a separate subdirectory (which is often how addon and subdomains default in a shared environment) and you should have a separate .htaccess file in each subdirectory. Not one for all.

UPDATE#1: Try adding an exception to the WordPress .htaccess to specifically exclude any rewrites if accessed via the subdomain. For example:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]

    RewriteCond %{HTTP_HOST} !^subsite\.example\.net$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>  
# END WordPress

However, this really shouldn't be necessary since (as mentioned in comments), the mod_rewrite directives in the standalone app's .htaccess file should completely override these (because the standalone app is in a subdirectory).

The other caveat with adding code to the WordPress block is that this might be overwritten with the next update.

UPDATE#2: Alternatively, try adding the RewriteOptions directive to the standalone app's .htaccess file (located in a subdirectory):

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteOptions IgnoreInherit
    :

If this works then it would seem to suggest there is a RewriteOptions InheritDown[Before] directive in the server config which is allowing the mod_rewrite directives in the parent directory to be inherited. Note that IgnoreInherit and InheritDown[Before] are Apache 2.4+ features.

(EDIT: It seems the OP is on Apache 2.2.31, so the above directive results in a 500 Internal Server error.)

UPDATE#3: You could also try removing the RewriteBase / directive from both .htaccess files and remove the slash prefix in the WordPress RewriteRule substitution to match the rules in the standalone app's .htaccess file. So, the WordPress .htaccess file becomes:

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

The last line previously read: RewriteRule . /index.php [L] (ie. with a slash prefix). The slash indicates a root-relative URL-path, without the slash it's now relative to the directory that contains the .htaccess file.

MrWhite
  • 11,643
  • 4
  • 25
  • 40
  • Can you check the update on the OP and let me know what I am doing wrong? – ReynierPM Nov 09 '16 at 16:02
  • Presumably the `.htaccess` file for the standalone app is located at `/public_html/plataforma/.htaccess` and there are no other directives in the WP `.htaccess` file in the parent directory? If so, then the `.htaccess` file (or rather, the mod_rewrite directives) for the standalone app should be completely overriding the parent `.htaccess` file - so it should work? Do you know if `RewriteOptions` has been set in the server config (although on shared hosting you probably won't be able to)? What actually happens when you try to access the standalone app? – MrWhite Nov 09 '16 at 16:15
  • I can log in but as soon as I click on any internal link I am log out. I am seeing is the problem is coming from code which is weird because it works in the past (before I upgrade my account to have a dedicated IP) without too much headache but now is giving me all the issues mentioned here – ReynierPM Nov 09 '16 at 16:28
  • Do you see the correct domain/URL in the browser's address bar? Being logged out sounds like a cookie problem? I've added a suggestion to my answer (although this should be unnecessary). – MrWhite Nov 09 '16 at 16:39
  • Yes, I see the same URL but of course different script being executed with different parameters, but even with your latest suggestion isn't working. I will look at code for now and will be back if I had any other issues – ReynierPM Nov 09 '16 at 16:40
  • If that is working, then I've added an alternative suggestion to my answer, which might be preferable. – MrWhite Nov 09 '16 at 16:59
  • if I add that directive I end with 500 error. What I did is add it between the `RewriteEngine On` and `RewriteBase /` and keep the rest, is that fine? – ReynierPM Nov 09 '16 at 17:58
  • Ah, maybe my assumption is wrong in that case. (?) The complete example is simply the rest of the code from your `.htaccess` file. What version of Apache are you using? `IgnoreInherit` is an Apache 2.4+ feature, so if you are on Apache 2.2 then you will indeed get a 500 error. You could also try removing the `RewriteBase /` directive from both `.htaccess` files and remove the slash prefix in the WordPress `RewriteRule` _substitution_ to match the rules in the standalone app's `.htaccess` file. – MrWhite Nov 09 '16 at 18:16
  • The hosting seems to be using Apache 2.2.31 and what do you mean exactly by *remove the slash prefix in the WordPress RewriteRule substitution to match the rules in the standalone app's .htaccess file.*? – ReynierPM Nov 09 '16 at 18:19
  • I've updated my answer. – MrWhite Nov 09 '16 at 18:26
  • That doesn't work either I get the same behavior, I will check the code carefully before continue bothering you but thanks a lot – ReynierPM Nov 09 '16 at 18:28
  • Hhhmm, in that case, you'll probably need to fall back to UPDATE#1. Bit of a mystery why those rules appear to be inherited though. When you obtained the dedicated IP address you'll be on a different server config - so there would seem to be _something_ a bit different. – MrWhite Nov 09 '16 at 18:35