【问题标题】:htaccess : wildcard folders and urlhtaccess : 通配符文件夹和 url
【发布时间】:2013-08-12 21:33:14
【问题描述】:

我有一些域名,例如http://domain.com

http://domain.com/sport -> Folder actually exits

http://domain.com/sport/123/ - > Folder dont exist

http://domain.com/sport/123/hello.html - > file dont exist

所以当http://domain.com/sport/123/http://domain.com/sport/123/hello.html 被访问了。它必须显示第一个文件夹 index.php 的内容,而不是抛出 not found 错误,即在此示例中它必须显示 http://domain.com/sport/index.php 的内容

我尝试了下面的代码。但它会引发 500 内部错误

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/.*$ /$1/index.php [L]

【问题讨论】:

  • 查看您的 Apache 错误日志,了解 500 错误的原因。我在那个 .htaccess 代码中看不到任何语法上无效的内容。
  • 我正在通过 cpanel 做...你能告诉我如何检查 apache 错误吗?
  • 不,我不能。我不知道 cpanel 如何提供日志访问;您必须检查主机的文档。
  • 您可以将/$1/index.php 中的前导/ 删除为$1/index.php
  • @MichaelBerkowski : 没有不工作的先生

标签: .htaccess url-rewriting


【解决方案1】:

如果您将所有重写规则包装在 IfModule 容器中,您是否仍会收到 500 内部服务器错误?例如

<IfModule mod_rewrite.c>
   # Turn mod_rewrite on
   RewriteEngine On
   RewriteBase /

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([^/]+)/.*$ /$1/index.php [L]
</IfModule>

如果您停止收到错误,但重写仍然无法正常工作,则意味着您必须打开重写模块。这完全取决于您的设置、托管服务设置和/或您是否有权访问httpd.conf 文件。

【讨论】:

    猜你喜欢
    • 2020-01-23
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 2017-10-08
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多