【问题标题】:.htaccess how to show "index.php" in url.htaccess 如何在 url 中显示“index.php”
【发布时间】:2019-12-15 14:14:33
【问题描述】:

你好,我创建了一个小 cms 来学习 mvc,但我遇到了一个非常基本的问题。

通常我的域之后的整个 url 会显示在一个变量中,但如果我输入单词“index”我的变量是完全空的。

我的 index.php:

<?php

$url = $_GET['url];

echo $url;

?>

这是我的 .htaccess

RewriteEngine On

Options +FollowSymLinks

RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

所以如果我输入以下网址:

"localhost/~username/mycms/indexabc" 结果 => indexabc

"localhost/~username/mycms/index" 结果 =>

"localhost/~username/mycms/index.php" 结果 =>

"localhost/~username/mycms/index.php2" 结果 => index.php2

任何人知道我应该怎么做,我的 .htaccess 也会重定向 index 和 index.php?

我的 httpd.conf 文件:

<Directory "/Users/Sam/Sites/">
  Options Indexes FollowSymLinks Multiviews
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    仅当满足这些条件时才应用规则:

    RewriteCond ${REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    

    条件意味着仅当您的 URL 不是现有目录、文件或文件系统链接时才会应用它们。我确定文件 index.php 存在,所以这就是 localhost/~username/mycms/index.php 不起作用的原因。

    我认为在mycms 目录中也存在名称为index 的文件或目录。这可能是localhost/~username/mycms/index 不起作用的原因。

    【讨论】:

      【解决方案2】:

      我按照本教程进行操作,但在我的本地主机上它不起作用。

      https://www.youtube.com/watch?v=Aw28-krO7ZM&t=1191s

      我的文件夹中有index.php,但没有文件夹。

      这让我很困惑,因为我不明白我的本地主机出了什么问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-21
        • 1970-01-01
        • 2012-04-22
        • 2016-10-31
        • 2012-01-08
        • 1970-01-01
        • 1970-01-01
        • 2011-05-20
        相关资源
        最近更新 更多