【问题标题】:Accessing `folder/index.php` by default using `.htaccess`?默认情况下使用`.htaccess`访问`folder/index.php`?
【发布时间】:2013-01-13 10:21:08
【问题描述】:

我想把它设为默认:

来自:

mydomain.com/folder/folder/

到:

mydomain.com/folder/folder/index.php

无论如何在.htaccess做?

【问题讨论】:

  • 您想在地址栏中显示mydomain.com/folder/folder/index.php 而不是mydomain.com/folder/folder/

标签: .htaccess rewrite subdirectory


【解决方案1】:

这会将所有两个级别的文件夹从 /f1/f2/ 重定向到 /f1/f2/index.php 并在地址栏中显示它。它重定向 /f1/f2/f1/script.php(没有尾部斜杠)

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php   [NC]
RewriteCond %{REQUEST_URI}  ^/(\w+)/(\w+)/$
RewriteRule .*       %1/%2/index.php               [R,L]

【讨论】:

  • 感谢@Olaf 这解决了问题,但现在又产生了另一个问题:动态内容显示不正确
  • @amir2000 直接调用mydomain.com/folder/folder/index.php时动态内容是否正确呈现?
  • 是的。只有当我添加新规则时,它才会显示链接而不是图像。
  • @amir2000 请查看更新后的答案,将$ 附加到第二个RewriteCond
猜你喜欢
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
  • 2012-02-29
  • 2012-02-15
  • 1970-01-01
  • 2010-12-02
  • 2012-11-24
  • 1970-01-01
相关资源
最近更新 更多