使用htaccess的掩盖域和文件夹名称 [英] Use htaccess to mask domain and folder name

查看:119
本文介绍了使用htaccess的掩盖域和文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用htaccess以及mod_rewrite的掩盖一个域和它的两个子文件夹与另一个领域。例如: http://example.com/sub/sub-sub/ http://example-2.com/ http://example-2.com/ 是显示在浏览器地址栏,但含量 HTTP: //example.com/sub/sub-sub / 是什么显示在页面上。

I'm trying to use htaccess and mod_rewrite to mask one domain and two of its sub-folders with another domain. For example: http://example.com/sub/sub-sub/ to http://example-2.com/ So that http://example-2.com/ is what shows in the browser address bar, but the content of http://example.com/sub/sub-sub/ is what's displaying on the page.

我发现这个的问题/答案,要做到这一点,但它当我实现它不能正常工作。

I found this question/answer which should accomplish this, but it doesn't work when I implement it.

目前htaccess的:

Current htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+) [NC]
RewriteRule .*   http://example.com/sub/sub-sub/%1 [L]

Options -Multiviews

下面是我的目录的看法:

Here's a view of my directory:

推荐答案

您不必逃避 - ,除了一个字符类中。而且即使在那里,你可以把它作为转义的第一个或最后一个字符。

You don't need to escape -, except inside a character class. And even there, you can have it unescaped as the first or last character.

在一个重写规则的,图案被针对测试URL的路径,而不是域。如果你需要测试的域,您可以使用的RewriteCond

In a RewriteRule, the pattern is tested against the URL-path and not the domain. If you need to test against the domain, you can use a RewriteCond

RewriteCond %{HTTP_HOST} !example-2.com
RewriteRule ^/?sub/sub-sub/(.*) http://example-2.com/$0 [R,L]

RewriteCond %{HTTP_HOST} example-2.com
RewriteCond %{REQUEST_URI} !^/?sub/sub-sub
RewriteRule .* sub/sub-sub/$0

这篇关于使用htaccess的掩盖域和文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆