.htaccess 帮助 - Codeigniter

.htaccess help - Codeigniter

我目前有一个 .htaccess 文件来重写 index.php 的所有基础 URL,例如 example.com/index.php/home -> example.com/home

我的public_html文件夹根目录下的.htacces文件如下:

RewriteEngine on
RewriteCond  !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]

据我所知,这会重写所有 /URL 而非 images, css, resources, etc.. 以指向 index.php

我现在正尝试向我的 .htaccess 添加一条规则以重写 example.com/forums -> fourms.example.com

根据现行规则,当我尝试访问 forums.example.com 时收到 500 - Internal Server Error。我也尝试了以下无济于事:

RewriteEngine on
RewriteCond  !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
RewriteCond %{REQUEST_URI} ^/forums(.*)
RewriteRule ^forums(.*)$ http://forums.example.com [R=301,L]

如何更改这些规则以允许重定向 index.php 并将 example.com/fourms 重写为 fourms.example.com

今天第二次,我在发布问题后瞬间找到了答案:

RewriteEngine on
RewriteCond  !^(index\.php|images|css|resources|forums|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
RewriteCond %{REQUEST_URI} ^/forums(.*)
RewriteRule ^forums(.*)$ http://forums.example.com [R=301,L]

我不得不从第一次重写中排除 /forums,并在第二次重写中添加。