开发者

htaccess rewrite base url

Anyone out there good with htaccess and mod rewrite - i need your help!

I need to rewrite the base part of a url.

for example all requestst to http://domain1.com need to go to http://domain2.com

The requests will typically be in the form as follows:

http://domain1.com/main/test?q=1

i then need to go to http://domain2.com/main/te开发者_运维知识库st?q=2

Pleas help!

Thanks in advance


Try this in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# redirect for http
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]  
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/?(.*)$ http://domain2.com/$1 [R=301,QSA,L,NE]

# redirect for https
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]  
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/?(.*)$ https://domain2.com/$1 [R=301,QSA,L,NE]

R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA will append your existing query parameters

$1 is your REQUEST_URI


Rewriting URL's across multiple domains? I'm not entirely sure this can work, considering Apache's request-handling algorithm. You're looking for a redirect, not rewrite.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜