Redirecting domain B's subfolders to Domain A

ajax20

Verified User
Joined
Jul 16, 2014
Messages
142
Hi

I have a website with two domain names. The first, example.com, serves as the site's main domain, the one under which I originally installed Moodle. Then I set another domain, that is, example.org, simply as another way of accessing the website. Now, my problem is: since I have installed Moodle under example.com/moodle, if somebody change the .com in the address to .org, the website gives the following message:

"Incorrect access detected, this server may be accessed only through "http://example.com/moodle" address, sorry.
Please notify server administrator.

And then after a few seconds redirects to the correct address.

What I want to achieve is a method of redirecting any such incorrect accesses to the site's main address, that is, example.com.

Any ideas would be appreciated. Thanks

PS: I've read similar posts saying such cases can be done with the help of .htaccess. But I am not very good at that. Please let me know what lines I should add to .htaccess file if that is the right solution at all.
 
Hello,

The issue and its possible solution has nothing to do with DNS, so I moved the thread to another subforum.

If you want to redirect requests and want to use .htaccess file then you should learn mod_rewrite and documentation on how to built correct rules.

That might be something like this (you should place it in /moodle/ folder):

Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www.[COLOR=#333333]example.com[/COLOR]$
RewriteRule ^(.*)$ http://www.[COLOR=#333333]example.com[/COLOR]/$1 [R=301,L]

that's up to you check it and make sure it's working as intended.
 
Thanks

Hi zEitEr

Thanks for the advice. Yes, I'll have to learn the mod_rewrite commands, for sure.

Unfortunately, the codes did not work. The page still redirects to the page I mentioned before.

Any ideas, any one?

Many thanks
 
Please, make sure to have the rules at the very top of your .htaccess file. And make sure to read mod_rewrite documentation to correct the rules to make the to work for you. You've got the idea now, so that's up to you to implement it.
 
Back
Top