[英]CodeIgniter : URL rewriting not working
I have a website created with CodeIgniter, and although the URL Rewriting is working on my local installation (WAMP), it fails on my distant server. 我有一个使用CodeIgniter创建的网站,尽管URL重写在我的本地安装(WAMP)上有效,但在我的远程服务器上却失败。
The CI framework is installed in the "/dev" folder. CI框架安装在“ / dev”文件夹中。
Here's the error when I try to access a controller using the following URL : http://www.mywebsite.com/dev/controller 当我尝试使用以下URL访问控制器时,这是错误: http : //www.mywebsite.com/dev/controller
Not Found
未找到
The requested URL /dev/index.php/controller/ was not found on this server.
在此服务器上找不到请求的URL /dev/index.php/controller/。
I've tried every combination of .htaccess and config.php, but I can't figure out what's wrong. 我已经尝试过.htaccess和config.php的每种组合,但是我不知道出了什么问题。
However, http://www.mywebsite.com/dev/ works just fine. 但是, http: //www.mywebsite.com/dev/可以正常工作。
Here's the .htaccess file : 这是.htaccess文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And the application/config/config.php file : 和application / config / config.php文件:
$config['base_url'] = '/dev/'; # I tried to put the whole path, didn't work either
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING'; # I tried every possibility, none of them work
$config['url_suffix'] = '';
What's really weird is that this exact configuration used to work on another server, I moved my code today and it doesn't work now... 真正奇怪的是,这种精确的配置曾经可以在另一台服务器上工作,我今天移动了代码,现在不起作用了...
Any idea ? 任何想法 ?
You're not using a query string in your rewrite rules, you're using path info . 您没有在重写规则中使用查询字符串,而是在使用path info 。 Try changing the uri protocol to:
尝试将uri协议更改为:
$config['uri_protocol'] = 'PATH_INFO';
And if that still doesn't work, try changing your rules to append a query string instead: 如果仍然无法解决问题,请尝试更改规则以附加查询字符串:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?$0 [PT,L]
# ^------ a "?" here instead of "/"
And make sure the htaccess file is in the dev
directory. 并确保htaccess文件在
dev
目录中。
try it 试试吧
RewriteEngine On
RewriteBase /your_project_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and bingo 和宾果游戏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.