使用htaccess进行URL重写会在子域中产生500内部服务器错误

时间:2014-02-11 05:18:53

标签: .htaccess codeigniter subdomain

我正在使用此代码重写htaccess

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

它可以在 example.com/sub 中正常使用,但在 sub.example.com 中,它会提供500 internal server error(目标网页除外)。< / p>

我无法理解这里有什么不妥。有时它可能很简单。我正在使用GoDaddy。

错误日志。

[Tue Feb 11 00:32:51 2014] [11333226] [core:error] [client 122.174.192.156:15900] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Feb 12 03:03:37 2014] [11333226] [core:error] [client 122.174.232.6:16075] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://sub.example.com/
[Wed Feb 12 03:03:37 2014] [11333226] [core:error] [client 122.174.232.6:16069] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://sub.example.com/
[Wed Feb 12 03:03:37 2014] [11333226] [core:error] [client 122.174.232.6:16079] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://sub.example.com/
[Wed Feb 12 03:03:38 2014] [11333226] [core:error] [client 122.174.232.6:16081] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://sub.example.com/
[Wed Feb 12 03:03:40 2014] [11333226] [core:error] [client 122.174.232.6:16082] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer http://sub.example.com/

4 个答案:

答案 0 :(得分:2)

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

这适合我。

答案 1 :(得分:0)

您可以尝试以下代码:

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

答案 2 :(得分:0)

试试这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

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

假设 index.php 是您的索引页。

并更改config.php

$config['index_page'] = '';

答案 3 :(得分:-1)

即使正确编写了.htaccess,我也遇到了同样的问题。我花了一点时间才意识到文件权限是错误的。 DOH !!!

重要提示: PHP文件不得具有777权限。如果您尝试打开具有此类权限的PHP文件,则会导致内部服务器错误500&#34;。要解决此问题,只需将文件的权限更改为644或755.