根域上的 WordPress 站点可以正常工作,但子文件夹中的 codeigniter 无法正常工作

WordPress site on root domain works BUT codeigniter in subfolder not working

我已经花了 7 个小时挠头,但无法让我的 codeIgniter 目录正常工作。虽然,我在根域上的 wordpress 工作正常。问题出在 codeigniter 子文件夹上。

下面是我的根域的 Wordpress .htaccess:(根域工作)

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

下面是我的 CodeIgniter .htaccess 子文件夹:(不工作 404

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

一切都干净利落。上面应该是什么问题? 我还尝试添加 web.config 文件并认为这可行但没有成功。下面是web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Clean URL" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
         <staticContent>
                  <mimeMap fileExtension=".json" mimeType="manifest/json" />
         </staticContent>
    </system.webServer>
</configuration>

为了让解释更清楚。下面是我的 uri_protocol 属性:

$config['uri_protocol'] = 'AUTO';

我不会在此处粘贴网站 link 以避免有人将我标记为垃圾邮件。如果有人需要看,请在下面评论。

您可以尝试将您的目录从重写中排除。

RewriteCond %{REQUEST_URI} !^/(thedir|thedir/.*)$

thedir 替换为您的目录名称。

你的 wordpress .htaccess 应该像下面这样:

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

之后您应该可以使用

访问您的目录
http://yourdomanin.com/chat/

我在问题上面发布的文件非常好。这个问题只是因为 codeigniter 的控制器。如果控制器的任何文件的第一个字母是小写的,那么它就不会被打开,并且会给你 404 错误。尽管小型大写字母在 Godaddy 上效果很好,因为我已经这样做了很长时间。但它们不适用于 HostGator 托管。

因此,请确保控制器中的每个文件都必须以大写字母开头。谢谢!