【问题标题】:.htaccess redirect all requests to index.php even if the requested file exists.htaccess 将所有请求重定向到 index.php,即使请求的文件存在
【发布时间】:2013-06-24 10:32:12
【问题描述】:

我正在编写我的第一个 .htaccess 文件。我想知道如何将localhost/home/user/ 重写为localhost/index.php?home&id=user,即使存在“home”目录。

这可能吗?

【问题讨论】:

  • 你的意思不是反过来吗?就像从 localhost/home/user 到 localhost/index.php?home&id=user?否则你可以简单地使用 PHP 来做到这一点
  • sry...是的,我的意思是...

标签: .htaccess url rewrite


【解决方案1】:

这样做是一种不好的做法,但是,如果你真的想要这个,你需要的行是:

RewriteEngine On
RewriteBase /

#(things you want to do beforehand)

RewriteCond %{HTTP_REFERER} !^$
RewriteRule !^http://localhost/index.php?home&id=user [R,L]
#(things you want to do after redirect)

(您可能需要$1 而不是“用户”,具体取决于您使用的安全性;如果使用来自 Apache 的 .htpasswd,则来自 PHP 的$_SERVER['PHP_AUTH_USER']
你当然可以添加不同的标志,RewriteRule Flags 文档是here

【讨论】:

  • 不客气(也请用 +1 来爱我,不仅仅是将我的答案标记为解决方案!:P)
猜你喜欢
  • 2016-11-30
  • 2015-04-10
  • 2012-12-07
  • 1970-01-01
  • 1970-01-01
  • 2012-12-09
  • 2016-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多