Apache: How can i redirect all sites on the server to an URL? - apache

I have a VPS based Centos/cPanel-WHM. I wanna redirect all sites (including all pages & subdomains) on the server to one URL. How can i do this?

create .htaccess file in every website DocumentRoot dir which you want to redirect
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://exampledomain-redirect.com/

At webserver layer (change the .htaccess), you could issue 301 redirects for any requests to your sites to new URL
OR
you could inject javascript (through your web layer) or your code layout framework OR manually
at the head of the page to complete a redirect.
OR
if your domains point to different hosting.. you could upate their NS to point to your new location and do 1 OR 2

.htaccess is the best way, Otherwise change the document root for each site.

Related

How to set up a subdomain for subpage redirects

I'm working on a multi-site web server hosting both WordPress and MediaWiki. My WordPress site is at https://example.com, and I want the MediaWiki site to be at https://wiki.example.com. Since MediaWiki uses /mediawiki or /mediawiki/index.php in its URLs, I would need both of those to result in a usage of the subdomain (for instance, https://www.example.com/mediawiki/index.php/Main_Page should change to https://wiki.example.com/Main_Page). I assume this requires 1) editing of the DNS records with my domain registrar and 2) redirects added to my .htaccess file.
What do I add to my DNS records to allow for the subdomain?
What do I add to .htaccess to remove /mediawiki from the URL?

How to set rule for 303 redirect?

I have internal links like: http://example.com/payment/
If to enter this link instead http://example.com/payment I get an error 303.
How to configure .htaccess for redirect?
Add this redirect into your .htaccess file.
This allows you to redirect your entire website to any other domain
Redirect 303 / http://example.com/payment/
Redirecting a URL: Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to
keep the old page. For example, if you use index.html as your index
file and then later rename index.html to home.html, you could set up a
redirect to send users from index.html to home.html.
For example:
Redirect /path/to/old/file/old.html http://www.example.com/new/file/new.html
You can find more detailed examples here.

How to disable default website for server when subdomain is not found?

I have multiple websites hosted on server using Webmin panel version 1.660
If I enter existing subdomain like www.domain2.com everything works fine, but for non-existing subdomains like wwwa.domain2.com server loads page from domain1.com
Is there any way to disable this feature?
I would like that non-existing subdomains would show 404 error or would be redirected to appropriate domain.
If you are using Apache, search Google for 404 redirects and url rewriting. Also if you want to take it future, then you also need to configure your DNS to catch all subdomains and redirect to your HTTP server

Redirect all traffic from one folder to another

I have a blog hosted at say domain.com/site but have built a new website. I want to redirect all traffic from domain.com/site/anything to domain.com/home/ so that any traffic going to any page or file on the old site gets redirected to the new homepage.
I am unsure what code to place in the .htaccess file and also where on the server to place it
Simply:
Redirect 301 {old path} http://domain.com/{new path}
you can place that at the root of your website, with the old path and Apache will redirect to the new site.
In your case:
Redirect 301 /site/anything http://domain.com/home

replacing domain names using .htaccess

I have a new website as http://abc.com/case_studies/casstudy20/.
I have an old website as http://xyz.com/clients/home.php?client=myclient
There are loads of case studies and stories under old domain that is xyz.com. Now that I am using abc.com is it possible to replace the URL, so it shows abc.com but access the code from the same old place.
meaning when my users goes to old site instead of xyz.com. It should say http://abc.com/clients/home.php?client=myclient. But runs from the same old xyz.com.
Is it possible to do it using htaccess.
Sort of. You can redirect all the traffic from xyz.com to the proper path on abc.com but this requires you to maintain control of both domains.
If you can, it's actually better to put this in the virtual host config for xyz.com then you don't need a complete configuration at all. Assuming you have permissions it will work in .htaccess as well though.
RedirectMatch ^(.*)$ http://www.abc.com$1
If you can keep control of both domains then you are looking for a http 301 redirect. You can do that by adding the following line to your htaccess file to redirect an entire website. Without control of your original domain it's impossible for your old xyz.com website to be routed to the appropriate server so your htaccess file will never have anything to redirect.
redirect 301 / http://abc.com/