【问题标题】:remove index.php from url using .htaccess使用 .htaccess 从 url 中删除 index.php
【发布时间】:2014-11-10 07:37:11
【问题描述】:

我正在使用 Ubuntu。服务器也是linex。我的框架是codeigniter。 我的.htaccess 代码在本地工作,但不在服务器上。 我正在使用 .htaccess 删除 index.php 我的服务器网址就像 http://xx.xxx.xxx.xxx/foldername/index.php/signup 。这里 xx.xxx.xxx.xxx 是 http_host。

我的 .htaccess 代码是

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/

#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_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

#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]
</IfModule>

我已经在$config['index_page'] = '';中设置了配置

所有代码都在本地主机上运行。但在服务器上它不起作用。

请告诉我如何从 url 中删除 index.php ?

【问题讨论】:

  • 你的网址是/index.php/signup ??通常 index.php 配置为 index.html 之后的默认文件,所以只需尝试删除 index.html。

标签: php .htaccess codeigniter


【解决方案1】:

你需要有这样的/foldername/.htaccess

RewriteEngine on

RewriteBase /foldername/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

那么在/foldername/application/config/config.php你需要有这些配置设置:

$config['base_url']     = '';
$config['index_page']   = '';
$config['uri_protocol'] = 'AUTO';

【讨论】:

    猜你喜欢
    • 2021-10-02
    • 2015-01-20
    • 2023-03-07
    • 2011-05-20
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多