我想要使用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
相关推荐
最新文章