【问题标题】:Neither XAMPP or the live website is rendering the index.php automaticallyXAMPP 或实时网站都不会自动呈现 index.php
【发布时间】:2018-10-02 03:38:59
【问题描述】:

自从我在我的根文件夹中添加了一个 .htaccess 文件(至少那时我开始注意到有问题):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

我的网站从未自动登陆 index.php 文件。要查看实时结果: www.unidrones.co.za/ChoiceGelatin

该页面应该呈现 index.php 文件并自动突出显示“HOME”链接,就像我在 URL 中手动键入 index.php 时所做的那样:www.unidrones.co.za/ChoiceGelatin/index.php

一方面,它正在读取索引文件的内容,但与之关联的 CSS 不起作用。每个页面都有一个动态添加的正文 ID,因此索引文件的正文标记的 ID 为#index。

我在 SO 和其他论坛上进行了研究,并看到了类似的问题,并在尝试时检查了所有内容:

  1. 编辑 Apache 配置文件(检查)
  2. 从 allowOverrite All 中删除 # 注释(检查)
  3. 在 cPanel 上编辑 htaccess 文件(检查)
  4. 删除 htaccess 文件(检查)
  5. 将 DirectoryIndex index.php 放在 .htaccess 文件中(检查)
  6. 这个问题很接近,但仍然不适用get the index.php with .htaccess
  7. 其他一些不值得一提的解决方案(检查全部)

以上解决方案均无效。我在 XAMPP 上尝试了该网站并进行了直播,但都没有像昨天一样正常显示。

【问题讨论】:

  • 你在 apache http.conf 文件中启用了 mod_rewrite 吗?
  • httpd.conf 文件中唯一的 mod_rewrite 行是这个,它没有被注释掉,所以我假设它是启用的:LoadModule rewrite_module modules/mod_rewrite.so

标签: php .htaccess


【解决方案1】:

将 index.php 添加到您的根目录中:

<?php
header('Location: ' . ('http://www.unidrones.co.za/ChoiceGelatin/index.php'));
?>

这会将您重定向到 ChoiceGelatin 的索引页面。 .htaccess 中的重写规则实际上消除了每次请求 php 文件时添加 .php 的负担。但它似乎不起作用,可能是因为 http.conf 中的配置。 Try enabling mod-rewrite!

【讨论】:

  • @ArabianMaiden 两个链接都呈现相同的 php 文件。 scripts.php 中的 javascript 负责样式(具体是 here 类)
  • 这是一个明智的解决方法,但是我需要知道我做错了什么,因为直到昨天一切都在按应有的方式工作......将来我更不想使用header() 函数,而是让它按应有的方式工作
  • @ArabianMaiden 好吧,我不确定。也许您有一个不同的 .htaccess 文件,它可以正确地将任何 url 重定向到正确的位置并将其删除。或者你之前也有一个索引页面?
猜你喜欢
  • 1970-01-01
  • 2020-10-25
  • 2016-02-14
  • 1970-01-01
  • 2016-05-01
  • 2018-08-08
  • 1970-01-01
  • 2013-02-16
  • 1970-01-01
相关资源
最近更新 更多