【问题标题】:.htaccess all request to other file.htaccess 对其他文件的所有请求
【发布时间】:2012-09-22 20:07:58
【问题描述】:

目前我有以下 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>

效果最完美。

它将像 http://domain.com/something/ 这样的 url 重新写入 public/index.php 文件,就像一个魅力,除非它是一个文件,就像它应该的那样。

但是http://domain.com(没有附加任何路径)(根目录中没有index.php,所以它现在给出404)没有被重写,我怎样才能改变这个.htaccess所以它重写这个url也是?

索引文件在 public/index.php 我希望它通过使用 .htaccess 来加载该文件

谢谢

【问题讨论】:

  • 如果你的 htaccess 文件在你的文档根目录下?

标签: php apache .htaccess rewrite


【解决方案1】:

我相信要重写根目录,您可以简单地按照以下方式进行操作:

RewriteRule ^$ location/of/root/file [L]

【讨论】:

    【解决方案2】:

    你可以试试:

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ public/index.php
    

    RewriteBase 应该在规则模式前面加上一个斜杠,强制它匹配根路径。

    未经测试!

    【讨论】:

      【解决方案3】:

      你那里的东西是受 WordPress 启发的??这是一个坏主意,因为它告诉 Apache 在重定向之前始终检查路径是文件还是目录。

      我有这样的事情

      RewriteEngine On
      RewriteCond %{REQUEST_URI} !^.*/(css|images|javascript)(.*) [NC]
      RewriteCond %{REQUEST_URI} !\.(swf|ico|php|xml)$ [NC]
      RewriteCond %{REQUEST_URI} !robots.txt
      RewriteRule (.*) index.php?page=$1&%{QUERY_STRING} [PT]
      

      第一个条件限制此重定向在特定文件夹中工作。 秒为特定的扩展。 你可以猜到第三个做了什么:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-04
        • 2012-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-10
        相关资源
        最近更新 更多