大家好,我试图从url中隐藏index.php,嗯,类似的东西:
我想要:mydomain.com/index.php/mycontroler
类似于:mydomain.com/myntroler
这是我的.htaccess
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index.php|images|robots.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
这是我的conf.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
问题是它在本地运行良好,但在服务器中运行不好
这是我的文件的处理方式
- bin
- etc
- mail
- public_ftp
- public_html
-- application
-- assets
-- system
-- .htaccess
-- index.php
帮助
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
如果仍然遇到问题,请尝试更改:
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'AUTO';
或者其他不同的选项(在config.php中,您可以找到uri_procol参数的所有可用选项)
这是.htaccess的东西,
<IfModule mod_rewrite.c>
Options +FollowSymLinks -Indexes
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /
# Restrict your site to only one domain
#RewriteCond %{HTTP_HOST} !^www.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
#prevent access to htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory browsing
Options All -Indexes
IndexIgnore *
在config.php 中
- 将基本URL设置为"http://www.example.com/'
- 将$config['index_page']设置为空
- string Set$config['uri_procol']='REQUEST_uri'
所有我的.htaccess
RewriteEngine on
RewriteCond $1 !^(index.php|robots.txt|static)
RewriteRule ^(.*)$ /index.php/$1 [L]
并且您应该确保属性AllowOverride
设置正确,例如:httpd.conf
目录段中的AllowOverride ALL
在root.htaccess文件中进行以下更改
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
它对我有效。