htaccess 重写基本 url

发布于 2024-09-28 08:45:45 字数 504 浏览 1 评论 0 原文

任何擅长 htaccess 和 mod 重写的人 - 我需要你的帮助!

我需要重写 url 的基本部分。

例如,所有对 http://domain1.com 的请求都需要转到 http://domain2.com

请求通常采用以下形式:

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

然后我需要去 http://domain2.com/main/test?q=2

请帮忙!

提前致谢

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/test?q=2

Pleas help!

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无语# 2024-10-05 08:45:45

在您的 .htaccess 文件中尝试此操作:

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 将附加您现有的查询参数

$1 是您的 REQUEST_URI

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

琉璃繁缕 2024-10-05 08:45:45

跨多个域重写 URL?考虑到 Apache 的请求处理算法,我不完全确定这是否可行。您正在寻找重定向,而不是重写

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文