Apache子域重定向

发布于 2024-12-28 12:51:28 字数 607 浏览 3 评论 0原文

我有一个子域(称为 subdomain.mydomain.com)

我只想将一个页面(例如:www.mydomain.com/page1.php)重定向到我的子域

因此,当我加载 subdomain.mydomain.com 时,我想转到 www .mydomain.com/page1.php 但在 url 中保留我的子域

使用 htacess 或 virtualhost

这是我编辑的代码和您的评论

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mysite\.fr$ [NC]
RewriteRule ^index\.php/?$ http://apropos.mysite.fr/? [NC,L,R]

RewriteCond %{HTTP_HOST} ^apropos\.mysite\.fr$ [NC]
RewriteRule ^$ http://www.mysite.fr/index.php?com=who [L,P,QSA]

I have a subdomain (called subdomain.mydomain.com)

I just want that a page (ex: www.mydomain.com/page1.php) redirects to my subdomain

So when i load subdomain.mydomain.com i want to go to www.mydomain.com/page1.php but conserving my subdomain in the url

Using htacess or virtualhost

here is my edited code with your comments

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mysite\.fr$ [NC]
RewriteRule ^index\.php/?$ http://apropos.mysite.fr/? [NC,L,R]

RewriteCond %{HTTP_HOST} ^apropos\.mysite\.fr$ [NC]
RewriteRule ^$ http://www.mysite.fr/index.php?com=who [L,P,QSA]

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

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

发布评论

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

评论(2

另类 2025-01-04 12:51:28

您可以在 ROOT .htaccess 中尝试以下代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# Redirects www.mydomain.com/page1.php?com=who to subdomain.mydomain.com
RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^page\.php/?$ http://subdomain.mydomain.com/? [NC,L,R]

# Internal Redirect(Proxy) subdomain.mydomain.com to www.mydomain.com/page1.php?com=who
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^$ http://www.mydomain.com/page.php?com=who [L,P,QSA]

You can try following code in your ROOT .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# Redirects www.mydomain.com/page1.php?com=who to subdomain.mydomain.com
RewriteCond %{QUERY_STRING} (^|&)com=who(&|$) [NC]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^page\.php/?$ http://subdomain.mydomain.com/? [NC,L,R]

# Internal Redirect(Proxy) subdomain.mydomain.com to www.mydomain.com/page1.php?com=who
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^$ http://www.mydomain.com/page.php?com=who [L,P,QSA]
音盲 2025-01-04 12:51:28

因此,当我加载 subdomain.mydomain.com 时,我想访问 www.mydomain.com/page1.php 但在 url 中保留我的子域

尝试将以下内容放入站点根目录中的 .htaccess 中。我假设您的子域和域共享相同的根。

RewriteEngine on
RewriteBase /

# page (ex: www.mydomain.com/page1.php) redirects to my subdomain
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#do not redirect if from proxy
RewriteCond %{QUERY_STRING} !(^|&)r=1(&|$) [NC]
RewriteRule ^page1\.php/?$ http://subdomain.mydomain.com [NC,L,R=301]


#if subdomain.mydomain.com
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
#and root directory, then proxy to page1
RewriteRule ^$ http://www.mydomain.com/page1.php?r=1 [P,L]

So when i load subdomain.mydomain.com i want to go to www.mydomain.com/page1.php but conserving my subdomain in the url

Try putting the following in the .htaccess in the root directory of you site. I am assuming that your subdomain and domain share the same root.

RewriteEngine on
RewriteBase /

# page (ex: www.mydomain.com/page1.php) redirects to my subdomain
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
#do not redirect if from proxy
RewriteCond %{QUERY_STRING} !(^|&)r=1(&|$) [NC]
RewriteRule ^page1\.php/?$ http://subdomain.mydomain.com [NC,L,R=301]


#if subdomain.mydomain.com
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
#and root directory, then proxy to page1
RewriteRule ^$ http://www.mydomain.com/page1.php?r=1 [P,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文