假设我有以下URL
子域example.com/myfolder
其中"myfolder"是CI安装的根文件夹(应用程序文件夹所在的位置)。
我有以下。htaccess(归功于Fabdrol和Elliot Haughin):
<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吗?Thx
*仅供参考*我还试图更改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).
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
我想我可能已经用这个配置解决了它:
我的.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)不在我的根目录(public_html)中,我需要将RewriteBase从"/"修改为"/path_to_your_application"
事实证明,如果你正在创建一个名为"subdomain"的子域,它会在你的public_html中创建一个名称为"submain"的文件夹,你应该将其视为子域的根。因此,我将"重写库"设置为"/myfolder",而不是"/my_subdomain_folder/myfolder"。
我希望这个解决方案能帮助其他人。
谢谢大家的帮助和提示。
只需添加一个?在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