I have tried solving this on my own but I can't seem to figure it out.
Here is what I'm trying to do:
Create a 301 redirect of all URLs (including index) on subdomain.example.com to example.com .
So for example:
This means that I DO NOT want to keep the same URL structure that's used on subdomain.example.com. I just want URLs on the subdomain to point to the index on the example.com. I know that's not the best solution for SEO, but that's how I want it.
I have tried accomplish this using
Redirect 301 / https://example.com/
but that keeps the URL structure and I don't want that.
So how can I solve this?
You can not achieve this with a Redirect
as it appends the old URL path to new one. You can use RewriteRule
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule (.*) https://example.com/ [R=301,L]
according to the documentation https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect
keeps the part of the url.
With redirectMatch you can use regexes and substitution to rewrite your url eg
RedirectMatch 301 . https://example.com/
where the dot (.) is a match anything.
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.