假设我有以下网址
subdomain.example.com/myfolder
其中“myfolder”是我的CI安装的根文件夹(应用程序文件夹所在的位置)。
我有以下.htaccess(致Fabdrol& ElliotHaughin的信用):
<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>
当我尝试访问我的网站时,例如:
subdomain.example.com/myfolder/controller/etc...
它始终返回5xx内部服务器错误。但是,如果我添加
subdomain.example.com/myfolder/index.php/controller/etc...
完美无缺。我很确定我的.htaccess有问题我只是没有看到问题所在。
有人可以帮我修理我的htaccess吗? THX
* FYI * 我还尝试在config.php上更改以下行
$config['index_page'] = ''; // Originally set to index.php
$config['uri_protocol'] = 'REQUEST_URI' // Originally set to AUTO
当我改变:
RewriteEngine On
RewriteBase /myfolder
它不会返回500,但它根本不显示任何内容。
只是提供一些关于myfolder结构的信息
public_html
---|
|
|--mysubdomain_folder
| |
|-----|--myfolder (my website where index.php, .htaccess and application folder are).
答案 0 :(得分:1)
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
答案 1 :(得分:0)
我想我可能已经使用这种配置解决了它:
我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myfolder
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
我的config.php文件:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
事实证明,由于我的应用程序(我的ci_root)不在我的root(public_html)中,我需要将RewriteBase从“/”修改为“/ path_to_your_application”
事实证明,如果您创建一个名为“subdomain”的子域,它将在您的public_html中创建一个名为“subdomain”的文件夹,您应该将其视为子域的 root 。因此我将我的RewriteBase设置为“/ myfolder”而不是“/ my_subdomain_folder / myfolder”。
我希望这个解决方案可以帮助其他人。
感谢大家的帮助和提示。
答案 2 :(得分:0)
只需添加一个?在index.php之后
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets)
RewriteRule ^(.*)$ index.php?/$1 [L]
我还建议让我们查看文件而不是目录:
Options -Indexes