【问题标题】:Why .htaccess dose not route to my index.php?为什么 .htaccess 不路由到我的 index.php?
【发布时间】:2014-04-16 10:47:03
【问题描述】:

我创建了.htaccess,内容为:

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

所以,我期待:http://mydomain.com/command/paramater1 被定向到 index.php,但不会发生这种情况,而是出现 404 错误。

但是,http://mydomain.com 将打开 index.php

我的网站目录是这样的:

public_html/index.php public_html/.htaccess

我启用了mod_rewrite

有什么想法吗?

编辑

http://mydomain.com/command/paramater1 时我期待的是读取 index.php 中 url 中的命令并采取相应措施,但正如我所提到的,index.php 没有打开,而是 404 错误

【问题讨论】:

  • 你想重写所有的索引吗?使用^ 而不是.
  • 您能否通过添加此问题的答案来编写正确的 .htaccess 文件?谢谢
  • 您在 Apache 服务器上? Windows 服务器会忽略 .htaccess,除非你有某种特殊的插件,而且我不认为 nginx 使用相同的格式。
  • 是的,我在 Apache 服务器上,而不是 windows...

标签: php .htaccess mod-rewrite routes


【解决方案1】:
<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    #RewriteBase /path/to/app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>

当 mod_rewrite 模块处于活动状态时,这会将每个页面重新路由到 index.php

【讨论】:

  • 。本来也可以的。你要做的就是匹配任何东西
  • 是的,两者都是。和 ^ 工作,但你能解释一下 Options -MultiViews VS Options +FollowSymLinks 吗?还有 !-f 和 !-d 是什么意思? [QSA,L] ?
猜你喜欢
  • 2013-09-22
  • 1970-01-01
  • 2015-02-06
  • 2014-03-21
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多