简体   繁体   English

htaccess网址重定向,带有子域和路径

[英]htaccess url redirect with subdomain and path

I've got two subdomains connected to two domains and a path and I need to redirect to aa new domain with the same subdomain without the path ie 我有两个子域连接到两个域和一个路径,我需要重定向到具有相同子域的新域而没有路径,即

www.subdomainone.olddomain.com/path/article -> www.subdomainone.newdomain.com/article
www.subdomainone.olddomaintwo.com/path/article -> www.subdomainone.newdomain.com/article

www.subdomaintwo.olddomain.com/path/article -> www.subdomainone.newdomain.com/article
www.subdomaintwo.olddomaintwo.com/path/article -> www.subdomaintwo.newdomain.com/article

I am not familiar with htaccess rules and I have tried using the testers online but cannot solve my problem 我不熟悉htaccess规则,并且尝试过在线使用测试仪,但无法解决我的问题

Apache has url rewrites set of simple regex that let you do any king of such operation, all incomming traffic URL wil be rebuild before pointing to the right path (if is that what are you looking for). Apache具有一组简单的正则表达式的url rewrites集,可让您执行任何此类操作,在指向正确的路径(如果您要查找的是什么)之前,将重新构建所有传入的通信URL。

Write storng rules that do not rebuild old URLs that stay the same. 编写存储规则,这些规则不会重建保持不变的旧URL。

A mor trustes solution (as you migrated to new urls) is to rewrite all old URLs but not prompt users to the page but rather sending to the user a redirect HTTP to the new url so you avoid the physical user using them and they will be forgotten in a short time. mor信任的解决方案(当您迁移到新的url时)是重写所有旧的URL,但不提示用户进入页面,而是向用户发送重定向到新url的HTTP,这样您就避免了物理用户使用它们,在短时间内被遗忘。

You can use this generic rule on olddomain 's site root .htaccess: 您可以在olddomain的网站根目录.htaccess上使用此通用规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.olddomain\.com$ [NC]
RewriteRule ^(?:fr(?:-ca)?/)?(.*)$ http://www.%1.newdomain.com/$1 [L,NC,R=302]
example request:     
http://subdomain.olddomain.com/path/article/pme

htaccess 

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.olddomain\.com$
RewriteRule ^(?:path(?:-pathy)?/)?(.*)$ http://%1.newdomain.com/$1 [R=301,QSA,L]

This accounts for a hyphen in the path also for a dynamic subdomain.

new url: http://subdomain.newdomain.com/article/pme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM