简体   繁体   中英

How to redirect a URL to subdomain, when it is in the same directory?

I'm trying to redirect a URL to a subdomain, but the directory for the subdomain is in the root of the main, so I keep getting a redirect loop error.

OLD URL - http://thisisimysite.com/instruments/award/mbac-18-g
NEW URL - http://legacy.thisismysite.com/instruments/award/mbac-18-g

Here is what I've tried (I've added line breaks just for readability):

Redirect 301 
/instruments/award/mbac-18-g 
http://legacy.thisismysite.com/instruments/award/mbac-18-g

˄I get a redirect loop error.

Redirect 301 
http://thisismysite.com//instruments/award/mbac-18-g
http://legacy.thisismysite.com/instruments/award/mbac-18-g

˄Nothing happens at all.

*Note: The legacy.thisismysite.com directory (/legacy) is within the root directory of thisismysite.com. I don't want to redirect all old urls from main to legacy, as some are on main now and some need to move to legacy.

EDIT:

Here is my full .htaccess file:

<IfModule mod_rewrite.c>

Options +FollowSymLinks

# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /

# ignore legacy folder/subdomain
RewriteCond %{REQUEST_URI} "/legacy/"
RewriteRule (.*) $1 [L]

# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

# Remove trailing slash from ALL urls
# ------------------------------
RewriteRule ^(.*)/$ $1 [R=301,L]

#Redirect 301 
#http://thisismysite.com//instruments/award/mbac-18-g
#http://legacy.thisismysite.com/instruments/award/mbac-18-g

RewriteCond %{HTTP_HOST} ^thisismysite\.com$ [NC]
RewriteRule ^instruments/award/mbac-18-g?$     http://legacy.thisismysite.com/instruments/award/mbac-18-g [R=302,L]

</IfModule>

Give this a try and see how it works for you.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^thisismysite\.com$ [NC]
RewriteRule ^instruments/award/mbac-18-g/?$ http://legacy.thisismysite.com/instruments/award/mbac-18-g [R=302,L]

Change 302 to 301 when you've tested and it works.

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