.htaccess change domain but keep path

2019-08-30 17:09发布

i don't even know whether this is possible or not.

i've 3 domain names:

mytest.com test88.com test99.com

mytest.com is the main domain where all the content is located. in my case it is wordpress which is installed on that webspace.

my htaccess looks like this:

RewriteEngine On    

RewriteCond %{HTTP_HOST} ^(.*)test88.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test88 [R,L]

RewriteCond %{HTTP_HOST} ^(.*)test99.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test99 [R,L]

i want to keep the domainname in case a visitor goes to test88.com but i also want to keep the rest of the path. It should look like this in the address-bar: http://www.test.88.com/wp/?page_id=10&test=test88

ist this possible?

thanks in advance

1条回答
冷血范
2楼-- · 2019-08-30 17:32

Do you want the content from mytest.com show up under the test88.com and test99.com, basically creating duplicates ?

In that case you probably don't want to mod_rewrite to redirect [R], but to reverse-proxy [PT] the content from the main domain.

RewriteEngine On    

RewriteCond %{HTTP_HOST} ^(.*)test88.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test88 [PT,L]

RewriteCond %{HTTP_HOST} ^(.*)test99.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test99 [PT,L]

Make sure mod_proxy is installed on your Apache.

查看更多
登录 后发表回答