Codeigniter mod-在 apache 中重写,删除 index.php
Codeigniter mod-rewrite in apache, removing index.php
所以我对 codeigniter 很陌生,我一直在努力从我的本地站点中删除 index.php,在查看其他类似问题后,我设法让它适用于主页在 SO 上,但是 none 已经完全正常工作了。每当我访问我网站上的另一个页面时,它都会在我的屏幕上显示 wamp 页面。这是我在 codeigniter/.htaccess
中的代码
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</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>
我也把我的 apache/conf/httpd.conf
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
但还是没有运气,是不是我漏掉了什么?提前致谢
按照以下步骤操作:
1. 像这样更改配置文件:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Use 以下 .htaccess:
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
注意:.htaccess
因服务器而异。我的一些服务器(例如:Godaddy)需要使用以下 .htaccess
:
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]
使用此 .htaccess 适用于大多数服务器
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/[=10=] [PT,L]
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
您可以取消注释最后两行以强制使用 HTTPS。
这个也可以
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
注意第二个 .htaccess 的第 3 行 RewriteBase /foldername/ 使用此 RewriteBase / 如果您的脚本可以在不包含文件夹名称。
所以我对 codeigniter 很陌生,我一直在努力从我的本地站点中删除 index.php,在查看其他类似问题后,我设法让它适用于主页在 SO 上,但是 none 已经完全正常工作了。每当我访问我网站上的另一个页面时,它都会在我的屏幕上显示 wamp 页面。这是我在 codeigniter/.htaccess
中的代码<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</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>
我也把我的 apache/conf/httpd.conf
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
但还是没有运气,是不是我漏掉了什么?提前致谢
按照以下步骤操作: 1. 像这样更改配置文件:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Use 以下 .htaccess:
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]
注意:.htaccess
因服务器而异。我的一些服务器(例如:Godaddy)需要使用以下 .htaccess
:
RewriteEngine on
RewriteCond !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L,QSA]
使用此 .htaccess 适用于大多数服务器
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/[=10=] [PT,L]
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
您可以取消注释最后两行以强制使用 HTTPS。
这个也可以
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
注意第二个 .htaccess 的第 3 行 RewriteBase /foldername/ 使用此 RewriteBase / 如果您的脚本可以在不包含文件夹名称。