【问题标题】:htaccess rewriterule not working in codeigniterhtaccess rewriterule 在 codeigniter 中不起作用
【发布时间】:2015-04-25 22:36:46
【问题描述】:

我正在尝试从我的 codeigniter 应用程序的 URL 中删除 index.php。

为此,我这样编写 .htaccess 文件:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
# RewriteBase /projectname/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [PT]

它在 xx.xx.xx.xxx 服务器和 mydomain.com 中运行。在这里,我尝试将相同的副本复制到另一台服务器 yy.yy.yy.yyy。在这种情况下,重写 URL 不起作用。如果我使用'yy.yy.yy.yyy/index.php/login',它工作正常。但是“yy.yy.yy.yyy/login”,它会抛出“在此服务器上找不到请求的 URL /projectname/login。”错误。

【问题讨论】:

    标签: php .htaccess codeigniter rewrite


    【解决方案1】:

    对于你的主目录 .htaccess 试试这个,然后从 config.php 中删除 index.php

    Options +FollowSymLinks
    Options -Indexes
    
    <FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
        Order deny,allow
        Deny from all
    </FilesMatch>
    
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    

    不要触摸应用程序目录中的 .htaccess 文件。

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多