.htaccess - Masking and redirecting to a subdirectory on another server

I am looking for some help in my .htaccess file.

In short, I have a bunch of content in the www.myserver.com/forum/ subdirectory (this directory is not my choice and cannot be changed), which includes both the forum ( myserver.com/forum/forum ) and the wiki ( myserver.com/forum/wiki ) and this is obviously not a perfect layout. I do not own myserver.com, and there is content that is not mine, although I have full access to the entire server.

I also have a domain name www.mydomain.com , which I want to redirect and disguise in such a way that if the user goes to mydomain.com/<something> , they will be shown the contents from myserver.com/forum/<something> , while displayed mydomain.com/<something> in the address bar.

One more thing I would like to see, although this is not vital, for 404 generated by someone typing in mydomain.com/somethingThatDoesNotExist , should redirect to mydomain.com/404.php instead of myserver.com default 404.

I tried several different approaches and searched extensively on the Internet for the last day or so - I’m sure that the answer even here is on SO somewhere, but all the manuals / examples that I tried worked, and I feel like gathering in circles.

Thank you very much in advance.

EDIT: And I know for sure that .htaceess is included.

+6
source share
2 answers

if the user goes to mydomain.com/, they will be shown the contents from myserver.com/forum/ until mydomain.com/ is displayed in the address bar.

First of all, you need to understand that this is ONLY possible if mod_proxy enabled on the Apache mydomain.com mod_proxy .

Once you have included mod_proxy, mod_rewrite and .htaccess via httpd.conf on mydomain.com , put this code in your .htaccess in the DOCUMENT_ROOT directory:

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteRule ^(.*)$ http://myserver.com/$1 [L,P] 

I will need to think a little about your 404 requirement, but if you get this working, I am sure that we can also find a workaround for this.

+1
source

You can do proxying using PHP or any other language that they allow.
See file_get_contents for a proxy server?

0
source

Source: https://habr.com/ru/post/950000/


All Articles