Redirecting a Wildcard Subdomain Properly - .htaccess

Not sure how to do this, I would like to Redirect a Wildcard SubDomain to either the main index or a 404, i have had a lot of sub-domains in the past and i am not using them any more so to eliminate redirecting each one i wanna redirect sub-domains that don't exist
Would appreciate if anyone knows how to get this done

Related

Setting up 301 redirects for multiple domains merging to single domain

I've got a tricky situation where four different websites are now merging into a single site. I'm trying to figure out the best way to handle 301 redirects for old URLs from these sites.
Here's an example for illustration. Say I have these four sites:
https://red.com
https://blue.com
https://green.com
https://magenta.com
And they're all now going to be living just at https://red.com.
Each of these sites had a "Team" page...
https://red.com/team/
https://blue.com/team/
etc.
Once I've pointed all the URLs to the same place, I'd like to see if someone tried to enter one of the previous URLs, and direct them to a specific new place on the site, e.g.:
URL Entered: https://blue.com/team/
301 Redirect: https://red.com/blue/team/
URL Entered: https://green.com/team/
301 Redirect: https://red.com/green/team/
etc.
Since folks may be coming from multiple different domains, I can't use standard relative 301 redirects in .htaccess for this. I'd like to just be able to point the DNS for these other domains to go straight to red.com, and then handle the 301 redirect logic there.
Any ideas on how to handle this?
You can simply use 302 temporary redirect rather than using 301 which is permanent.
** Also don't forget to clear previous 301 redirection caches on your web browser; if used.

Best way to Redirect

I currently have my Online Store as a Sub-Domain of my main site and my host is having all sorts of trouble getting the "wildcard" ssl certificate to work with the redirects and the CDN.
I am considering just moving the store to a sub-directory of the main site to rid us of the wildcard ssl.
My concern is that the Search Engines have the Store indexed as https://store.xxxxxxxx.com. When the wildcard ssl is gone and the sub-domain is no longer https how do I go about redirecting from the Sub-Domain to the new Sub-Directory.
Thanks
You can use Redirect in your .htaccess to redirect the user. This will require you to keep the subdomain operational.
Redirect 301 / http://example.com/store/
The 301 is a permanent redirect. Search engines are usually smart enough to index this result permanently.
I recommend you also notify the search engines with your changes to speed up the process. This process is different for each search engine.

.htaccess: Point Secondary Domain to Primary's Subdirectory

I have two domains on a VPS server, the primary "domain1.net" and the secondary "domain2.com". The website I have currently set up for domain2.com resides at domain1.net/subd1/subd2. I'm trying to create a rewrite rule for my .htaccess file so that whenever someone visits the site "domain2.com", "domain2.com/index.php", it grabs the page from "domain1.net/subd1/subd2", "domain1.net/subd1/subd2/index.php". I would like to do this while keeping "domain2.com" intact in the web address, instead of moreover redirecting it, and have all images/links appear from domain2.com.
From my understanding, it seems .htaccess's rewrite rule would be able to do such a thing, I just haven't figured out how the syntax would work. However, if there's a superior alternate method, I wouldn't be opposed to hearing it.
I appreciate anyone's help on this issue.

redirect from old mod-write to new one

So I had a mod re-write all set up for a client who was hosting their site on a shared server with GoDaddy. After nearly of year of working they contacted me and GoDaddy had changed something that made the re-write not work properly. It would work sometimes but not all the time. Anywway, it liked nice URLs such as http://siteurl.com/employee/19/ as opposed to http://siteurl.com/employee-19 from what I was reading it had something to do with it not ending in a slash but either way, the first one works now.
However is there a way to create a redirect from the old modrewrite rule to the new one. I tried this but had never really done rewrites on the htaccess file before so I could have set it up wrong.
redirect /employee-19 http://siteurl.com/employee/19/
But that spits back an error 301, any thoughts on how to fix this or is it just a lost cause at this point?
But that spits back an error 301, any thoughts on how to fix this or is it just a lost cause at this point?
A 301 is what you want. It tells browsers and search engine indexing bots that http://siteurl.com/employee-19 is equivalent to http://siteurl.com/employee/19/ but to use the latter from now on. The content has permanently moved from the first to the second URL.
If you want a more generalized form, you can use RedirectMatch:
RedirectMatch 301 ^/employee-([0-9]+) http://siteurl.com/employee/$1/

Trouble redirecting all pages in a folder to a page at root level

I've searched, tried various examples, and none, other than creating an explicit list of redirect statements seems to work.
The biggest issue I have is that, although I have access to deploy web pages to the site, I do not have access to any web hosting control panel - site access was inherited, and until now it's been fine, but I think that it is either running an old version of apache, or rewrite rules are not allowed.
Anywa, over the years, the site has changed several times, and after registering the site with Google Webtools, I found the list of pages that gave crawl errors, so created an HTACCESS file to deal with these.
Over the years, there have been folders deployed and named in camel case and all lower case, and so all I wanted to do was to redirect all files in a folder to the new folder in the .htaccess file level, i.e.
My .HTACCESS currently has 120 lines, and an example batch are as follows:
redirect 301 /challenge/stanley_steamer.htm /lsr_history.html
redirect 301 /challenge/stanley_steamer.html /lsr_history.html
redirect 301 /Challenge/index.htm /lsr_history.html
redirect 301 /Challenge/Record.htm /lsr_history.html
redirect 301 /Challenge/Stanley_Steamer.htm /lsr_history.html
redirect 301 /Challenge/Sponsors/Avery_Weigh-Tronix.htm /sponsors.html
redirect 301 /contact/index.html /contact.html
redirect 301 /design/details.html /design.html
redirect 301 /design/index.html /design.html
redirect 301 /Design/Engine-drive_train.htm /design.html
redirect 301 /Design/Rear.htm /design.html
redirect 301 /Design/Home_Page.htm /design.html
redirect 301 /Design/index.htm /design.html
As you can see, I have some cases where the folder name is camel, others lower, and other cases where there is a htm and an html file of the same name that is listed in the crawl error log.
All I want to do is, in the example above, redirect all pages from /Challenge/ and /challenge/ to lsr_history.html, but all files in /Challenge/Sponsors/ to sponsors.html.
I also have a huge list of individual team pages that I list one by one and each one redirects to the new team page.
I've tried examples like:
RedirectMatch 301 ^/[Cc]hallenge/ /challenge.html, but this returns a 'Error 404 Not found'.
Any ideas or examples of how I can cut down my htaccess file to simplify this will be gratefully received.
Regards
Martin
I wouldn't bother searching for cases inside the match string for this kind of thing if I could avoid it - have you tried just specifying the RedirectMatch in lowercase, and appending [NC] to the end of every line? (that will tell mod_rewrite to ignore case and match regardless, which may save you some time)
if you have collections of similarly-formatted rewrites, why not group them together with one particular set of rules for each? That way you could cover, for example, all incoming URLs with one subdirectory with one rule, and all incoming URLs with a single subdirectory one with another rule. If nothing else, it could help simplify viewing the .htaccess file :)
(Take everything I suggest with a massive dose of salt, I'm still getting to grips with the black magick of mod_rewrite myself)

Resources