【问题标题】:Apache htaccess file, where did I go wrong?Apache htaccess 文件,我哪里出错了?
【发布时间】:2012-07-04 11:40:18
【问题描述】:

真的找不到我的错误,我可以访问站点地图/链接,但所有其他人都给出了 404 Not Found 错误。

DirectoryIndex index.php index.php?page=home index.php?page=error
Options Indexes FollowSymLinks MultiViews

AllowOverride All
Order allow,deny
Allow from all

<IfModule mod_rewrite.c>
    RewriteEngine On

    # some other stuff #

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteBase /
    RewriteRule ^sitemap/?$ sitemap.xml.php [L]
    RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1 [L]
    RewriteRule ^products/?$ index.php?page=products [L]
    RewriteRule ^products/([0-9]+)/?$ index.php?page=products&id=$1 [L]
</IfModule>

非常感谢您的帮助,我绝对不喜欢 .htaccess 文件...

【问题讨论】:

  • 检查你的错误日志——显示了什么?
  • 同一行一定次数:[Wed Jul 04 02:56:30 2012] [error] [client 127.0.0.1] File does not exist: /var/www/home"
  • 那么……您确定问题出在您的 .htaccess 文件上吗?
  • 不,我真的开始认为问题可能来自我的 Apache 配置。

标签: apache .htaccess


【解决方案1】:

除了重写规则,你还有其他问题:

DirectoryIndex index.php index.php?page=home index.php?page=error

这意味着,对于文件夹,将按此顺序选择显示索引的文件(现有的第一个获胜):

  1. index.php
  2. index.php?page=home(这是文件名
  3. index.php?page=error(这是文件名

我怀疑这是你的意图。

下一步:

AllowOverride All

如果你已经在.htaccess 并且AllowOverride 是限制性的,这将无济于事,如果不是,那么没有必要再写这个了。

Order allow,deny
Allow from all

这基本上是说“允许每个人在任何地方”,无论如何这是默认设置。除非它在上层或 apache 配置中以某种方式受到限制,否则这是多余的。


至于重写:

RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1 [L]
RewriteRule ^products/?$ index.php?page=products [L]

无论如何,第二条规则都是多余的,永远不会达到(因为第一条也匹配)。


至于你看到的错误:

[Wed Jul 04 02:56:30 2012] [error] [client 127.0.0.1] File does not exist: /var/www/home"

这可能意味着DocumentRoot 定义存在问题。请发布您的VirtualHosts 配置。

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多