Php Codeigniter.htaccess规则存在问题
在我的Php Codeigniter.htaccess规则存在问题,php,apache,.htaccess,codeigniter,mod-rewrite,Php,Apache,.htaccess,Codeigniter,Mod Rewrite,在我的.htaccess文件(如中所述)中得到了这个,虚拟主机的apache设置如下所示: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] ServerName.local 服务器管理员webmaster@localhost ServerAlias www.fitness.local DocumentRoot/var/www/blast
.htaccess
文件(如中所述)中得到了这个,虚拟主机的apache
设置如下所示:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
ServerName.local
服务器管理员webmaster@localhost
ServerAlias www.fitness.local
DocumentRoot/var/www/blast
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
但是如果我想去http://fitness.local/events
它不工作,但http://fitness.local/index.php/events
正在工作。我已经为apache启用了mod rewrite,所以这也包括在内
如何修复此问题?在.htacess文件中尝试此方法,然后运行
<VirtualHost *:80>
ServerName fitness.local
ServerAdmin webmaster@localhost
ServerAlias www.fitness.local
DocumentRoot /var/www/blast
<Directory /var/www/blast>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这很好:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
#启用URL重写
重新启动发动机
#如果您的网站从一个文件夹开始,例如localhost/my_项目,那么
#您必须将其更改为:RewriteBase/my_project/
#如果您的站点从根开始,例如example.local/那么
#随它去吧
重写BASE/dude_代码/
#当index.php丢失时,保护应用程序和系统文件不被查看
重写第二个$1^(应用程序|系统|专用|日志)
#重写到index.php/access\u denied/URL
重写规则^(.*)$index.php/access_denied/$1[PT,L]
#允许直接显示以下目录和文件:
重写COND$1^(main\.php | index\.php | robots\.txt | favicon\.ico | public |资产| css | js |图像)
#不重写
重写规则^(.*)$-[PT,L]
#重写到index.php/URL
重写规则^(.*)$index.php/$1[PT,L]
将您的HTC访问权限更改为
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /dude_code/
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(main\.php|index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
打开httpd conf文件,检查mod rewrite是否已启用
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
然后重新启动Httpd
这对我来说总是有效的
谢谢使用此.htaccess访问您的项目 (应放在应用程序文件夹之外)
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
您删除了配置中的'index.php'了吗?@DamienPirsy是的,但没有修复。启用mod_rewrite后您重新启动了服务器吗?@MuhammadRashid是的,我删除了,但也没有帮助。请尝试设置$config['uri_protocol']='AUTO'感谢您的想法,但这并不能真正解决它。不起作用。也许我应该将.htaccess文件放在其他地方或smthn?:DRewriteBase/dude_code/将dude_code更改为您在htdocsBy的代码的完整路径,您的意思是,例如…?不,请给我一个路径示例,即/var/www/blast
,或者我应该给出什么样的路径?
LoadModule rewrite_module modules/mod_rewrite.so
AllowOverride All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>