HTAccess 重写:301 重定向索引但不是子域
我正在创建一个在线社区,并尝试设置一个开发服务器。
目前,我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个目标很简单:
如果您不想添加前缀,请删除
RewriteRule
中的 www。请回复评论并提供有关第二个目标的更多信息。我不明白测试平台部分。
Your first goal is simply:
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.