我在CodeIgniter中开发了我的项目,它在XAMPP服务器上运行良好但在WAMP服务器上不起作用。
我已经改变了
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
和.htaccess我
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
网站首页显示正确。但是,每当我点击任何链接时,没有链接工作主页以法语版本出现。
只有在URL中有index.php时,项目才能在WAMP上正常运行。
e.g。
http://localhost/codeigniter/welcome/view (This link doesn't work)
http://localhost/codeigniter/index.php/welcome/view (Links works properly)
答案 0 :(得分:5)
试试这个,它随处可见:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
答案 1 :(得分:4)
在httpd.conf
文件中启用mod_rewrite
在我的情况下,我在本地磁盘C上安装了WAMP
找到httpd文件只需导航到C:\wamp\bin\apache\apache2.2.6\conf
用记事本编辑器打开httpd.conf文件然后找到以下行:
#LoadModule rewrite_module modules/mod_rewrite.so
并取消注释
保存文件并重新启动Apache以使新设置生效。
答案 2 :(得分:0)
检查RewriteBase
文件中的.htaccess
。
它就像下面的
RewriteBase /your project folder name/
复制下面的代码并将其粘贴到您的.htaccess
文件
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /codeigniter/
#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]
#RewriteRule ^page/(.*)$ index.php?/#$1 [R=301,L,NE]
#如果我们没有安装mod_rewrite,那么所有404都是 #可以发送到index.php,一切正常。 #提交人:ElliotHaughin
ErrorDocument 404 /index.php;
希望它会对你有所帮助。并检查一件事,即你的网址。如果有任何〜符号,则
.htaccess
文件将不同。否则上面的代码将起作用。感谢。
答案 3 :(得分:0)
试试这个
RewriteEngine On //missed this
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]