【问题标题】:How to configut htaccess file on codeigniter public_html如何在 codeigniter public_html 上配置 htaccess 文件
【发布时间】:2013-05-06 13:37:30
【问题描述】:

我的文件结构如下:

application
public_html
       .htaccess
       index

application/config/config.php

       here i have set blank my base_url and index page

.htaccess

DirectoryIndex index.php
RewriteEngine on                       
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 

但如果我使用 index.php 她仍然在 httpd.conf

上使用 虚拟主机
<VirtualHost *:80>

    ServerAdmin webmaster@dab
    DocumentRoot "c:\wamp\www\dab\public_html"

    ServerName dab
    ServerAlias www.dab
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-acces.log" common

    <directory "c:\wamp\www\dab\public_html">
        Options FollowSymlinks
        AllowOverride None
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </directory>
</VirtualHost>

url不使用index.php有什么解决办法

提前致谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    确保您在 apache conf 中启用了 mod_rewrite 模块,然后尝试使用看起来更像这样的 .htaccess:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
    
        #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]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
        ErrorDocument 404 /index.php
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      在您的 application/config/config.php 文件中找到以下行

      $config['index_page'] = 'index.php';
      

      将变量设置为空,如下所示。

      $config['index_page'] = '';
      

      就是这样,它对我有用。

      如果它不起作用,请尝试用这些参数('AUTO'、'PATH_INFO'、'QUERY_STRING'、'REQUEST_URI'和'ORIG_PATH_INFO')一一替换以下变量

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

      【讨论】:

      • 正如你所说,但如果我在本地主机上它仍然无法正常工作,但我在这里添加了虚拟主机
      猜你喜欢
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 2013-02-28
      相关资源
      最近更新 更多