Reputation: 87
I have 5 URLs on a subdomain website http://subdomain.example.com
, and I want them to redirect to 5 other URLs on my main website, https://www.example.com/
.
Important: URLs do NOT have the same structure!
Example:
http://subdomain.example.com/url1
should redirect to https://www.example.com/ipsum
http://subdomain.example.com/url2
should redirect to https://www.example.com/lorem
etc.
How can I handle that?
UPDATE:
There is a play
folder (name of the subdomain) which contains the subdomain website files and a htdocs
folder which contains the www website files.
Here is the .htaccess
file in my play
folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Upvotes: 1
Views: 3994
Reputation: 13
Try this...
Redirect 301 http://subdomain.example.com/url1 https://www.example.com/ipsum
Redirect 301 http://subdomain.example.com/url2 https://www.example.com/lorem
Upvotes: 0
Reputation: 45829
Since the subdomain has it's own .htaccess
file, you don't need to specify the hostname as part of the redirect. And since you already have mod_rewrite directives in the subdomain's .htaccess
file, you should also use mod_rewrite for these redirects (to avoid conflicts). Otherwise, you'll need to specify these redirects one-by-one.
Try the following at the top of your subdomain's /play/.htaccess
file. Note that this needs to go before the existing directives in the file.
# Specific redirects
RewriteRule ^url1$ https://www.example.com/ipsum [R=302,L]
RewriteRule ^url2$ https://www.example.com/lorem [R=302,L]
The above would match a request for http://subdomain.example.com/url1
and redirect accordingly, etc.
Note that the RewriteRule
pattern (regular expression) does not start with a slash when used in a per-directory (.htaccess
) context.
Note that these are 302 (temporary) redirects. Change them to 301 (permanent) - if that is the intention - only once you have confirmed they are working OK (to avoid caching issues).
Upvotes: 2