htaccess重写基本网址 [英] htaccess rewrite base url
本文介绍了htaccess重写基本网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以使用htaccess和mod重写-我需要您的帮助!
Anyone out there good with htaccess and mod rewrite - i need your help!
我需要重写网址的基本部分.
I need to rewrite the base part of a url.
例如,所有对 http://domain1.com 的请求都需要转到
for example all requestst to http://domain1.com need to go to http://domain2.com
请求的格式通常如下:
http://domain1.com/main/test?q=1
然后我需要转到 http://domain2.com/main/test?q=2
请帮助!
预先感谢
推荐答案
在.htaccess文件中尝试以下操作:
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
将以https状态301重定向 L
将成为最后一条规则 NE
不用于转义查询字符串 QSA
将附加您现有的查询参数
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
是您的REQUEST_URI
$1
is your REQUEST_URI
这篇关于htaccess重写基本网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文