重定向主页而不影响其他规则

redirecting homepage without affecting other rules

我当前的 .htaccess 如下。

# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on

# Send request via index.php (if it's not an existing file/folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>

我想将我的主页重定向到另一个域,但保留所有 /sub/directories。 所以修改规则如下。

# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on

# Send request via index.php (if it's not an existing file/folder)
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

#redirect
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://example.com/ [L,R=301]    

<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>

现在所有 /sub/directories 都收到内部服务器错误。日志表明它正在循环。

有什么想法吗?

RewriteCond仅供下一个RewriteRule.

使用那个:

# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on

#redirect
RewriteRule ^$ http://example.com/ [L,R=301] 

# Send request via index.php (if it's not an existing file/folder)
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

<IfModule mod_php5.c>
    RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

<IfModule !mod_php5.c>
    RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>