[英]How to redirect from specific subdirectory to a subdomain via .htaccess?
I've been trying to redirect this URL (and all its substructures): 我一直在尝试重定向此URL(及其所有子结构):
http://example.com/archive/
to (and its corresponding substructures): 到(及其对应的子结构):
http://archive.example.com/
For example : http://example.com/archive/signature/logo.png ==> http://archive.example.com/signature/logo.png
例如 :
http://example.com/archive/signature/logo.png ==> http://archive.example.com/signature/logo.png
: http://example.com/archive/signature/logo.png ==> http://archive.example.com/signature/logo.png
I tried to generate an .htaccess rule using a generator and evaluating it by looking at the regex, which I can understand (I think). 我试图使用生成器生成.htaccess规则,并通过查看正则表达式对其进行评估(我认为)。
The result was the following rule: 结果是以下规则:
RewriteEngine On
RewriteRule http://example.com/archive/(.*) http://archive.example.com/$1 [R=301,L]
The way I see it, the server will proccess any URL that starts with http://example.com/archive/
, will capture the string that comes next and will change the whole initial portion with the subdomain structure and append the captured string. 从我的角度来看,服务器将处理以
http://example.com/archive/
开头的所有URL,将捕获下一个字符串,并使用子域结构更改整个初始部分,并附加捕获的字符串。
Unfortunately, this doesn't seem to work neither on my server, nor on online testing tools such as: http://htaccess.madewithlove.be/ 不幸的是,这似乎在我的服务器或在线测试工具(例如http://htaccess.madewithlove.be/)上均不起作用
Is there anything I'm missing there? 我在那里想念什么吗?
Thank you! 谢谢!
You should be able to try it this way. 您应该可以尝试这种方式。
RewriteEngine On
RewriteRule ^archive/(.*)$ http://archive.example.com/$1 [R=301,L]
Note that I did not make it dynamic as you didn't specific if you will have more URL's that need to work this way as well or not. 请注意,我没有使它动态化,因为您没有具体说明是否会有更多需要以这种方式工作的URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.