【问题标题】:Explanation of this .htaccess file此 .htaccess 文件的说明
【发布时间】:2014-02-11 20:42:25
【问题描述】:

我最近在我的网站根目录中添加了一个 .htaccess 文件,以实现我在这个问题中已经提出的问题:

Create blog post links similar to a folder structure

现在,最佳答案非常棒,它可以在 localhost 上运行,但在我的服务器上却不行。

老实说,我不太确定 .htaccess 中的这些语句的确切含义。如果有人能逐行解释,我将不胜感激。

这就是我所拥有的

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

标签: php regex .htaccess


【解决方案1】:
<IfModule mod_rewrite.c>              # If the module for rewrite is available
RewriteEngine On                      # turn it on
RewriteBase /                         # set / to the relative root path
RewriteRule ^index\.php$ - [L]        # don't rewrite index.php and stop the rest of the rules
RewriteCond %{REQUEST_FILENAME} !-f   # if file does not exist
RewriteCond %{REQUEST_FILENAME} !-d   # and file is not a directory
RewriteRule . /index.php [L]          # show the index page instead
</IfModule>                           # close the IfModule clause

我怀疑如果它在您的服务器上不起作用,那么根目录没有为域或服务器配置正确设置。您需要查看文件的放置位置以及如何配置 httpd.conf 以使用这些路径。

另外,下次 Apache 在这个模块上有一个 wonderful documentation,应该会更深入地涵盖我刚才所说的所有内容。

【讨论】:

  • 您的回答内容丰富,但不是解决方案。我赞成你的努力。谢谢。
【解决方案2】:

实际的问题是我的虚拟主机上没有启用重写。 所以我在我的虚拟主机中启用了它,现在一切正常。

<VirtualHost *>
             ServerName mysite.com
             DocumentRoot /var/www/html/mysite.com
        <Directory /var/www/html/mysite.com>
                Options FollowSymLinks
                AllowOverride all
        </Directory>
</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多