【发布时间】:2015-06-01 03:58:38
【问题描述】:
在使用 .htaccess 实现重定向 + 域屏蔽方面需要帮助。它正在部分工作。它适用于子页面和子目录,但不适用于域本身。
我有两个域“redir1”和“redir2”。 目标是使用 .htaccess 和像这样的掩码实现重定向:
http://redir2 —> http://redir1
http://redir2/sub.php —> http://redir1/sub.php
http://redir2/index.php —> http://redir1/index.php
并且显示给访问者的 url 必须保持他们输入的内容:
http://redir2
http://redir2/sub.php
http://redir2/index.php
但如果他们输入 http://redir1,他们应该会在 url 中看到 http://redir1。
每个域都有以下两个文件: 索引.php 子.php
这是.htaccess中的代码:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?redir2$ [NC]
RewriteRule ^ http://redir1%{REQUEST_URI} [L,NE,P]
对于在域(子页面和子目录)之后具有某些内容的所有请求都非常有效。例如:
http://redir2/sub.php
http://redir2/index.php
但如果我只输入 http://redir2/ 我会收到“未找到”错误:
The requested URL /index.html was not found on this server.
确实我没有 index.html 但我有 index.php 不添加index.html如何解决?
谢谢
【问题讨论】:
-
DirectoryIndex index.php在 redir2 htaccess 文件中解决了这个问题。然而,关于 Wordpress 的一个小说明。如果redir1是一个 Wordpress 站点,它有它自己的标准 WP htaccess 指令。它还会产生其他问题。例如,它可能会屏蔽子页面。但它不会屏蔽域,只是重定向到 redir1 而不屏蔽。
标签: php apache .htaccess mod-rewrite redirect