【问题标题】:Prevent server from going into a directory防止服务器进入目录
【发布时间】:2015-04-22 03:46:08
【问题描述】:

我有一个名为http://server.local/documents/ 的链接,我希望能够在http://server.local 的index.php 中回显documents/,而无需转到documents/ 目录。这可以使用 .htaccess 文件吗?如果是这样,我在里面写什么?

【问题讨论】:

  • 除了echo 'documents/';,我不确定你的意思是什么
  • @scrowler 当我输入http://server.local/documents/ 时,服务器会将我重定向到documents/ 目录。我希望能够在 http://server.local 的 index.php 中执行类似 echo "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 的操作,而无需服务器将我重定向到 documents/ 目录。

标签: php .htaccess url url-rewriting


【解决方案1】:

如果您希望所有请求都转到一个 PHP 页面,this 之类的内容可能适合您:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

【讨论】:

  • 成功了!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2020-04-15
  • 1970-01-01
  • 2020-08-22
  • 2021-06-22
  • 1970-01-01
  • 2012-06-22
  • 2010-09-23
  • 2014-07-07
相关资源
最近更新 更多