【问题标题】:htaccess Redirect One File to Anotherhtaccess 将一个文件重定向到另一个
【发布时间】:2014-04-21 00:48:18
【问题描述】:

我已阅读 this,这对于我的要求来说似乎太长了。

并尝试了Redirect /index.php /index2.php,但没有成功(内部服务器错误)

我想要的是将我的一些 php 文件重定向到索引。例如,我的索引文件为

header.php

内容.php

页脚.php

我想将对该文件的直接访问重定向到 index.php。是否可以使用 htaccess 或任何其他方式?

mysite.com/index.php 好的 mysite.com/header.php 重定向到 404 或索引或其他。

【问题讨论】:

  • “直接访问”是什么意思?由网络服务器提供的所有文件都可以直接访问。
  • 我认为我解释得很好。我正在使用 php include 方法创建我的设计。我想阻止对我包含的文件的直接访问。我想阻止一些文件 - 在这种情况下,header.php 和 footer.php - 被阻止。如果有人试图访问我的页面,没关系。如果有人试图通过 www.example.com/header.php 访问我的 header.php,我想重定向他们。

标签: .htaccess mod-rewrite redirect


【解决方案1】:

试试:

RewriteEngine On
RewriteRule ^(header|content|footer)\.php - [L,R=404]

RewriteEngine On
RewriteRule ^(header|content|footer)\.php index.php [L,R=301]

【讨论】:

  • 感谢您的回答。我做了 RewriteRule ^(header|content|footer)\.php index.php [L,NC] 并且看起来还可以。我应该使用 ac 301 404 等参数吗?有必要吗?
  • @Degauser "R" 标志重定向。 404 表示返回“404 Not Found”错误,301 表示永久重定向。
猜你喜欢
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 2020-05-04
  • 1970-01-01
  • 2022-01-13
  • 2016-02-01
  • 1970-01-01
相关资源
最近更新 更多