RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
在我的.htaccess
文件中(如https://www.codeigniter.com/user_guide/general/urls.html中所述)和虚拟主机的apache
设置如下所示:
<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>
然而,如果我想转到http://fitness.local/events
它不起作用,但http://fitness.local/index.php/events
正在发挥作用。我已经为apache启用了mod重写,所以这也被覆盖了。
我该如何解决这个问题?
答案 0 :(得分:0)
在.htaccess文件中尝试此操作然后运行
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
答案 1 :(得分:0)
这样可以正常工作:
<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>
答案 2 :(得分:0)
将您的htaccess更改为
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
打开httpd conf文件检查是否启用了mod-rewrite
LoadModule rewrite_module modules/mod_rewrite.so
AllowOverride All
然后重启你的Httpd。
这总是适用于我的情况。
由于
答案 3 :(得分:0)
将此.htaccess用于您的项目。
(应该将放在应用程序文件夹之外)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>