2

假设我有以下网址

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?谢谢

* 仅供参考 * 我还尝试在我的 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).
4

3 回答 3

1
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
于 2013-07-31T12:11:28.563 回答
0

I think i might have solved it using this configuration:

my .htaccess file:

<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>

My config.php file:

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

It turns out that since my application (my ci_root) is not in my root (public_html) i need to amend the RewriteBase from "/" to "/path_to_your_application"

And it turns out if you are creating a subdomain called "subdomain" it will create a folder inside your public_html named "subdomain" and you should treat this as the root of your subdomain. Hence i set my RewriteBase to "/myfolder" instead of "/my_subdomain_folder/myfolder".

I hope this solution could help others.

Thanks all for the helps and hints.

于 2013-08-01T01:40:27.177 回答
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
于 2015-06-04T07:44:42.450 回答