【问题标题】:Do not show php files in the folder as the home directory不要将文件夹中的 php 文件显示为主目录
【发布时间】:2018-10-11 21:01:43
【问题描述】:

我的文件在名为 Project 的文件夹中

链接看起来像这样 http://sitename.com/project/news.php

我怎样才能显示你喜欢的主目录 链接看起来像这样(不删除项目文件夹或不移动) http://sitename.com/news.php 来源/project/news.php

【问题讨论】:

  • 将文件移出目录
  • 您可以访问您网站的 apache conf 文件吗?
  • 是的,我有访问权限
  • 然后适当地设置DocumentRootDirectory 路径。听起来你只是把它们设置得太高了。

标签: php file root


【解决方案1】:

如果您在服务器上启用了 mod_rewrite 并且正在使用 apache

在根目录下创建一个名为 .htaccess 的文件

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^project(/.*|)$ $1 [L,NC]  
</IfModule>

【讨论】:

    【解决方案2】:

    您可以使用 mod_rewrite 在您的根目录中创建一个 .htaccess 文件:

    RewriteEngine On
    RewriteRule ^(.*)$ project/$1 [L]
    

    关于页面列表,你可以随意替换字符串:

    $files = scandir('/path_to_your_project-folder');
    foreach($files as $file) {
        echo 'http://sitename.com/' . $file; //clicking on this link the htaccess rule show the right page wrapping the real url
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-17
      • 2011-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多