简体   繁体   中英

How to redirect from specific subdirectory to a subdomain via .htaccess?

I've been trying to redirect this URL (and all its substructures):

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

I tried to generate an .htaccess rule using a generator and evaluating it by looking at the regex, which I can understand (I think).

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.

Unfortunately, this doesn't seem to work neither on my server, nor on online testing tools such as: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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