【问题标题】:Apache not showing index.html on address barApache 没有在地址栏上显示 index.html
【发布时间】:2013-06-19 17:43:17
【问题描述】:

我想在地址栏上显示我的 index.html 文件。当您转到http://www.example.com/ 将其重定向到http://www.example.com/index.html 并在地址栏上显示该 index.html。

编辑

这是我的 .htaccess 文件。我尝试过 neo 示例,但没有成功。

DirectoryIndex  naslovnica.php
Options -Indexes

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* 404.html [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /naslovnica\.php
RewriteRule ^naslovnica\.php$ http://example.com/naslovnica.php [R=301,L]

【问题讨论】:

  • 你试过了吗?

标签: apache mod-rewrite


【解决方案1】:

您必须查看 Apache DocumentRoot 目录。请查看以下 Apache 文档...

Apache DocumentRoot

您必须创建index.html 并将其放在DocumentRoot 目录中。

来自文档...

If your DocumentRoot "/usr/web" then an access to http://my.example.com/index.html refers to /usr/web/index.html.

已编辑
以下文档解释了隐藏索引。猜猜你也可以用它来取消隐藏索引。

Mod_Rewrite – Hide index.php

以下可能是寻找正确解决方案的开始...

Options +FollowSymLinks
RewriteEngine on
# Redirect client requests for www.example.com/ to "www.example.com/index.html" in main doamin
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html
RewriteRule ^index\.html$ http://www.example.com/index.html [R=301,L]

【讨论】:

  • 您好,感谢重播。 DocumentRoot 目录设置正确。我认为问题是 DirectoryIndex 指令。 DirectoryIndex index.html index.php。这意味着如果您在地址栏中输入example.com,它将显示 index.php 或 index.html 文件的内容,但不会在地址栏上显示文件名。我不知道如何强制 apache 显示文件名。
  • 我找到了this,其中有一些RewriteRule 的示例。希望这会有所帮助。
猜你喜欢
  • 2015-04-23
  • 2012-07-15
  • 2015-10-12
  • 2012-06-03
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 2015-08-25
相关资源
最近更新 更多