Ora*_*ind 114 php mod-rewrite codeigniter url-rewriting
如何"index.php"在中心某处的codeigniter中删除每条路径中的延伸?我想要干净的非index.php-fied URLs?
Sea*_*ira 89
如果您使用Apache,请在根网站目录中放置一个.htaccess文件,其中包含以下内容:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
另一个好的版本位于:
http://snipplr.com/view/5966/codeigniter-htaccess/
jim*_*087 60
删除index.php时遇到了一些大问题.作为一般规则,下面的.htaccess已在多个服务器上进行了测试,通常可以正常工作:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
Run Code Online (Sandbox Code Playgroud)
如果您没有任何运气,那么下一步是调整您的配置文件.尝试一些其他URI协议,例如
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
$config['uri_protocol'] = 'ORIG_PATH_INFO';
Run Code Online (Sandbox Code Playgroud)
如果您还没有运气,请尝试更改重写规则以包含您的子文件夹.如果您在开发服务器上使用临时URL等,这通常是一个问题:
RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
只要玩这些选项,一个应该工作.另外,请确保您的索引文件设置为:
$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
祝好运!
Sha*_*lin 31
将.htaccess文件与index.php文件一起放在应用程序根目录中.(检查htaccess扩展名是否正确,Bz htaccess.txt对我不起作用.)
并将以下规则添加到.htaccess文件中,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
然后在application/config/config.php文件中找到以下行
$config['index_page'] = 'index.php';
Run Code Online (Sandbox Code Playgroud)
将变量设置为空,如下所示.
$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
就是这样,它对我有用.
如果它不起作用,请尝试逐个替换以下变量('AUTO','PATH_INFO','QUERY_STRING','REQUEST_URI'和'ORIG_PATH_INFO')
$config['uri_protocol'] = 'AUTO';
Run Code Online (Sandbox Code Playgroud)
Re0*_*ess 21
看看system\application\config\config.php文件,有一个名为的变量index_page
它看起来应该是这样的
$config['index_page'] = "index.php";
Run Code Online (Sandbox Code Playgroud)
改为
$config['index_page'] = "";
Run Code Online (Sandbox Code Playgroud)
然后如上所述,您还需要向.htaccess文件添加重写规则
注意:在CodeIgniter v2中,此文件已移出系统文件夹 application\config\config.php
以上所有方法都失败了,然后我发现我没有将AllowOverride None更改为我的虚拟主机文件中的AllowOverride All / etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
...
Run Code Online (Sandbox Code Playgroud)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /codeigniter/index.php/$0 [PT,L]
Run Code Online (Sandbox Code Playgroud)
更改RewriteRule.*index.php/$ 0 [PT,L]后,项目文件夹名称为"codeigniter".为我工作.谢谢你们的支持.
步骤1 =>将.htaccess文件放在存在应用程序和系统文件夹的根文件夹中.
第2步=>如果你的网络路径使用子文件夹,如 - yourdomain.com/project/ - 那么在htaccess文件中使用以下代码
RewriteEngine on
RewriteBase /project/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project/index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
如果您的网络路径使用root文件夹,例如 - yourdomain.com - 那么在htaccess文件中使用以下代码
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
小智 5
只是想我可能会添加
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
将是.htaccess并确保以下列方式编辑您的application/config.php变量:
更换
$config['uri_protocol'] = “AUTO”
Run Code Online (Sandbox Code Playgroud)
同
$config['uri_protocol'] = “REQUEST_URI”
Run Code Online (Sandbox Code Playgroud)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Run Code Online (Sandbox Code Playgroud)
这绝对有用..试一试
| 归档时间: |
|
| 查看次数: |
120388 次 |
| 最近记录: |