HTAccess 重写:301 重定向索引但不是子域

发布于 2024-09-08 07:52:49 字数 936 浏览 0 评论 0原文

我正在创建一个在线社区,并尝试设置一个开发服务器。

目前,我使用 GIT 作为我的存储库。我同时拥有 mysite.com 和 mysite.net; .com 是主要站点。

我的目标:

  • 如果用户访问 www.mysite.net,他们就会 应该是 301 重定向到 www.mysite.com。

  • 如果用户访问 dev.mysite.net,他们应该被要求输入密码 然后带到测试平台..(在 mysite.net/ 上)

这可以通过一些巧妙的 htaccess 重写来完成吗?

编辑:

# Here is what I have so Far
RewriteEngine on

#
## Redirect normal users to mysite.com
#
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

#
## Redirect dev.mysite.net to root directory of mysite.net/
#
RewriteCond %{HTTP_HOST} ^dev.mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]


# REQUIRE Password for Dev Server
AuthUserFile /home/myaccount/public_html/mysite.net/.htpasswd
AuthGroupFile /dev/null
AuthName "Development Server"
AuthType Basic
require valid-user

I'm creating an online community and I'm trying to set up a development server.

Currently, I'm using GIT as my repository. I have both mysite.com and mysite.net; the .com being the primary site.

My Goal:

  • If a user goes to www.mysite.net they
    should be 301 redirected to
    www.mysite.com.

  • If a user goes to dev.mysite.net they should be asked for a password
    and then taken to the testbed.. (on mysite.net/)

Can this be done through some crafty htaccess rewrites?

EDIT:

# Here is what I have so Far
RewriteEngine on

#
## Redirect normal users to mysite.com
#
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

#
## Redirect dev.mysite.net to root directory of mysite.net/
#
RewriteCond %{HTTP_HOST} ^dev.mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]


# REQUIRE Password for Dev Server
AuthUserFile /home/myaccount/public_html/mysite.net/.htpasswd
AuthGroupFile /dev/null
AuthName "Development Server"
AuthType Basic
require valid-user

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

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

发布评论

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

评论(1

魄砕の薆 2024-09-15 07:52:49

您的第一个目标很简单:

# redirect to primary
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

如果您不想添加前缀,请删除 RewriteRule 中的 www。

请回复评论并提供有关第二个目标的更多信息。我不明白测试平台部分。

Your first goal is simply:

# redirect to primary
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.net$ [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

Remove the www in the RewriteRule if you don't want to prefix.

Please comment back with more information regarding the second goal. I don't understand the testbed part.

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