大网数据广告活动
服务器运维问答

.htaccess is stopping a site from works while WP sites does work, why?

· 52CE 我爱测

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 …

问题原文

原帖链接 · ReynierPM · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。