2

I'm completely new to the community and have a question which might seem stupid.

I've created a page in my Wordpress site (which is not finished yet) which I want to use as a landing page. However, I want this page to be seen as a subdomain of my website.

The website is event-lab.ro and the subdomain should be webdesign.event-lab.ro (which actually points to event-lab.ro/webdesign).

Now, what I want is to rewrite the Wordpress name as the subdomain, so that whenever someone goes to the link or someone inserts webdesign.event-lab.ro in the address bar, the name in the address bar stays webdesign.event-lab.ro.

I'm new to .htaccess, but I've combed the Internet and tried variations of code, with no luck.

Here's what I did:

1) I created a new folder named "webdesign" in my "public_html" folder (that being where my website is stored).

2) I created an .htaccess file in said folder with the following code...

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webdesign\.event\-lab\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.webdesign\.event\-lab\.ro$
RewriteRule ^(.*)$ "http\:\/\/event\-lab\.ro\/webdesign" [R=301,L]

3) And I also created an index.php file in the same folder, that simply load the Wordpress theme, environment and Template...

<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/

$_GET['page_id']=25140;

define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('../wp-blog-header.php');

4) I should point out that I'm using a childtheme.

I've tried all sorts of variations of the .htaccess code, but nothing works. Whenever I try to go to webdesign.event-lab.ro I'm simply redirected to event-lab.ro/webdesign.

Any ideas?

UPDATE: Ok, so after some more checks, my hosting company confirmed that mod_proxy is activated. However, the redirect still doesn't work right. If I use the proxy flag, the page doesn't display at all. It just keeps loading until it times out.

My current code in the .htaccess file is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webdesign\.event\-lab\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.webdesign\.event\-lab\.ro$
RewriteRule ^ http://event-lab.ro/webdesign [P]
MMotoca
  • 43
  • 1
  • 6

1 Answers1

0

There are two ways to modify the response to a request, rewrite and redirect.

  • Rewrite is just declaring, what should be sent to a client for some given request.

  • Redirect tells the client, where it should fetch the response.

A redirect is triggered explicitly by the R|redirect flag, or implicitly by giving a full external URL. In your case, you do both http://event-lab.ro/webdesign and R=301.

If the requested subdomain and the target document tree is located on the same server, you can just give the path component and omit the R flag.

RewriteCond %{HTTP_HOST} ^webdesign\.event-lab\.ro$ [OR]
RewriteCond %{HTTP_HOST} ^www\.webdesign\.event-lab\.ro$
RewriteRule ^ /webdesign [L]

Unrelated, you don't need to quote the target. And as an aside, never test with R=301!

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Thanksfor such a prompt response! – MMotoca Oct 15 '16 at 12:55
  • But now I'm getting a 404 error. Tried clearing the cache and the same happens. – MMotoca Oct 15 '16 at 12:56
  • Also, I've checked how the redirection is interpreted "formally" in CPanel, in the subdomain section. It now says that it redirects to http://webdesign.event-lab.ro/webdesign – MMotoca Oct 15 '16 at 12:58
  • Ok. So, I added the full path to the RewriteRule again, because it was clearly messing up the the redirrect. And I suppose that my problem is that I'm creaing a redirect from a subdomain name to a URL which is inside the site as a Wordpress page. But what I want to do is mask the subdomain, and I'm not sure how I can do that in the .htaccess file. – MMotoca Oct 15 '16 at 13:19
  • This means `webdesign.event-lab.ro` and `event-lab.ro` each have their own webspace. – Olaf Dietsche Oct 15 '16 at 13:23
  • Maybe the proxy flag works for you, see http://stackoverflow.com/a/39574451/1741542 – Olaf Dietsche Oct 15 '16 at 13:27
  • What exactly do you mean by webspace? As I've mentioned before webdesign.event-lab.ro simply point to a Wordpress PAGE in the same installation of Wordpress, namely event-lab.ro/webdesign. – MMotoca Oct 15 '16 at 13:28
  • Ițve tried Proxy before, but it had no effect. It still redirected without masking. – MMotoca Oct 15 '16 at 13:30
  • Webspace is where you put your HTML files, PHP scripts, etc. The proxy *flag* is different from the Proxy *directive*. – Olaf Dietsche Oct 15 '16 at 13:31
  • Well, if I replace the L flag with the P flag it, absolutely nothing happens. That is, when I insert webdesign.event-lab.ro into the address bar, the progress bar just keeps going on and on, and the site doesn't appear. I don't even get a timeout error. It just sits there. – MMotoca Oct 15 '16 at 13:35
  • Also remove the `R` flag and activate mod_proxy, please see the answer I linked. – Olaf Dietsche Oct 15 '16 at 13:37
  • I removed the R flag right after your first answer. This will be a stupid question, but how do I activate mod_proxy? If I understand correctly, I just add "a2enmod proxy proxy_http" after "RewriteEngine On"? – MMotoca Oct 15 '16 at 13:45
  • I just researched turning on mod_proxy. But I don't think I can do that, because I'm under a hosting service, and I don't have access to the mods-enabled directory. – MMotoca Oct 15 '16 at 13:59
  • And what's worse is that when I asked the hosting service to help me with the redirect issue they said that there was nothing they could do on the server side, and that it was a Wordpress issue (which even I as a nube understand is a stupid way to put it). – MMotoca Oct 15 '16 at 14:00
  • I also forgot to mention something. Initially I managed to make the redirect work with masking included. – MMotoca Oct 15 '16 at 14:56
  • But after I created a child theme, masking stopped working. Do you think it has something to do with this? – MMotoca Oct 15 '16 at 14:57
  • I just talked to my hosting company again, and because I don't have a dedicated server, they can't enable mod_proxy. Any other ideas? :( – MMotoca Oct 15 '16 at 15:23
  • No, unfortunately not. If both domains were pointing to the same webspace, the RewriteRule I posted should work. – Olaf Dietsche Oct 15 '16 at 15:28
  • Maybe, you can write a main page for `webdesign.event-lab.ro`, which fetches the content from `www.event-lab.ro/webdesign` with curl, and then delivers this to the client. That way, you need not fiddle with .htaccess, but can solve it with PHP. This would do more or less the same as the `P|proxy` flag. – Olaf Dietsche Oct 15 '16 at 15:31
  • I just updated my initial question, because the hosting company just confirmed that mod_proxy is enabled on the server. You can check my updated .htaccess code above. – MMotoca Oct 15 '16 at 15:48
  • This looks good so far. Look into the web server logs, both webdesign.e-l.ro and e-l.ro, and see what's going on. – Olaf Dietsche Oct 15 '16 at 15:54
  • Unfortunately I don't have access to the latest logs. The most recent ones are from October 10th, for some strange reason. But how would I go about solving this with PHP? – MMotoca Oct 15 '16 at 16:15
  • Ok. So, I've kept trying many variations and nothing's working. Maybe the mod_proxy isn't turned on. – MMotoca Oct 15 '16 at 19:32
  • How do I use PHP? If you look at my initial question, you'll see that I have an index.php file that calls up this specific Wordpress page and load the Wordpress environment, theme and template. – MMotoca Oct 15 '16 at 19:33
  • When you do a redirect `R`, the PHP doesn't matter, because the client sees the new URL and fetches the content from there. – Olaf Dietsche Oct 15 '16 at 19:37
  • If I don't use the index.php file, the redirection just goes to the parent directory of event-lab.ro/webdesign/. – MMotoca Oct 15 '16 at 20:04