homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

site1.com redirects to site2.com without changing url
My hosting provider says it can't be done?

 6:42 am on Apr 12, 2013 (gmt 0)

I am trying to set up several mobile websites, which are all hosted inside the same Wordpress CMS.

When I enter sample1.example.com into my web browser, it redirects to http://example.com/?pbcezmobsite=cafe-sample1-caevv which is correct, but the URL changes.

Can this be done? Ideally, the site behaves (all 7 pages) as though it is on sample1.example.com and then I can do the same thing with sample2.example.com and so on, pointing to different pages on example.com.

Thank you in advance. I have a hard time believing my support guy who says it can't be done. If you tell me here it can't be done, I'll believe it.


[edited by: engine at 8:58 am (utc) on Apr 17, 2013]
[edit reason] please use example.com [/edit]



 6:56 am on Apr 12, 2013 (gmt 0)

A redirect is an instruction from the website to the browser. It tells the browser to make a new request for a new URL.

If you want to access a site "but the URL stay the same" you need something other than a "redirect". You need an internal rewrite if the two sites are on the same server or a proxy passthrough if not.


 7:58 am on Apr 12, 2013 (gmt 0)

on the same server

I got the impression this is shared hosting. So it would have to be the same userspace, right? But the OP makes it sound as if the sites all live in the same place, so this should not be impossible.

This is all assuming you have full control of your htaccess file and can write any rules you need. You will need to proceed very carefully, because your CMS has already made an htaccess. You have to make sure not to conflict with any of its actions.

Start by explaining what the physical arrangement is. Do all of your domains live side by side in one userspace? Or do you have a primary domain, with "add-ons" in separate directories inside your first directory?


 3:01 pm on Apr 12, 2013 (gmt 0)

Lucy is correct. The CMS is a wordpress install that has been modified with a plug-in to create mobile websites as custom posts. I have multiple mobile websites inside the same Wordpress install.

My goal is to have my local business clients point their m. subdomain to my wordpress install, so that I can manage their site updates for them. I want to maintain their web address.

I can set up the subdomains on my server however I want. On the test site, I created a A Name record in their DNS to point to my hosting account IP address. On my server, I create a parked domain with their name, and a subdomain on that parked domain.

I can point the parked subdomain to its own directory or to the same directory that the Wordpress site is on. Right now, it is pointed to its own directory and a 301 redirect is in place to redirect it to the dynamic wordpress content.

The htaccess file has only an AddHandler line in it right now.

Do you have any suggestions as to how I might best accomplish this?


 9:02 pm on Apr 12, 2013 (gmt 0)

The htaccess file has only an AddHandler line in it right now.

If this is WordPress, that cannot possibly be the only thing in htaccess. There's got to be another htaccess file lurking around somewhere. Look in higher and lower directories.

Now, if there really is no WordPress-specific stuff in any htaccess anywhere within your userspace, then it's all happening in the host's config file. That's where I throw in the towel ;)


 10:54 pm on Apr 13, 2013 (gmt 0)

You are right, I was mistaken about the .htaccess file. Apparently I was looking at the directory above. The rewrite engine is on, there are rewrite conditions and rule for a 301 redirect.

A 301 redirect will not achieve what I am trying to accomplish. I am surprised that there is not a way to serve up a page in the CMS as the index.html for a subdomain. Wordpress has their multisite features, which performs a similar task--multiple websites in a single WP install, just not the way I want to do it.

What about subdomain forwarding with masking? That isn't a perfect solution, but might be acceptable. I suppose that something I would do with HTML... but is there a better way?


 11:49 pm on Apr 13, 2013 (gmt 0)

Okay, forwarding with masking appears to require html framing. That is no good. It creates too many problems with mobile browsers.

My gut tells me that there is a rewrite rule that will deliver the result I seek, but that is as far as I get.

What about rewriting with proxy throughput? [P]


 12:00 am on Apr 14, 2013 (gmt 0)

RewriteCond %{HTTP_HOST} ^sample1\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sample1\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/\?pbcezmobsite\=cafe\-sample1\-caevv" [P]

This worked for the index page, but not for the links. Is there a way to make it work for the links as well?

[edited by: engine at 8:58 am (utc) on Apr 17, 2013]
[edit reason] please use example.com [/edit]


 12:11 am on Apr 14, 2013 (gmt 0)

Instead of example.com/?pbcezmobsite=cafe-sample1-caevv
I can also use example.com/?post_type=pbcezmobsite&p=2017

I feel like I am getting closer, but I need a little encouragement at this point. :-) (not sure if there is an emoticon for being in over one's head.)

Could it be that what I am trying to accomplish (dynamic rewriting of pages in my Wordpress site to behave as a separate website) is just not practical? I do have the option of Wordpress Multisite, but I was really trying to find a more elegant solution.

[edited by: engine at 8:59 am (utc) on Apr 17, 2013]
[edit reason] please use example.com [/edit]


 5:44 am on Apr 14, 2013 (gmt 0)

dynamic rewriting of pages in my Wordpress site to behave as a separate website

That sounds kinda like an apples-and-oranges question. There are two different things:
the URL that the user sees
the physical directory that your physical files physically live in

It obviously saves trouble if they are approximately the same, so directory/subdir/filename.html refers to a file called filename.html which lives in a directory "subdir" which in turn lives in a directory "directory". For, uhm, a given definition of "physical location". ("If this bit has a magnetic charge, and this one and this one but not that one over there...")

This thread has meandered a bit. Was there a point where you laid out the two basics?
#1 what the various URLs are
#2 where the various files "really" live.

At any given time there are at least two threads in Apache with closely overlapping topics. This is no help either.


 7:51 am on Apr 14, 2013 (gmt 0)

This worked for the index page, but not for the links. Is there a way to make it work for the links as well?

Change the
^$ pattern to match requested URLs other than root. You might need one rule for root and another for the other pages.

 6:33 pm on Apr 14, 2013 (gmt 0)

g1smd, thank you. Would it be possible to provide a little more detail on what the ^$ pattern should look like? I am trying to understand regex but I am still rather new to this.


 1:00 am on Apr 15, 2013 (gmt 0)

Lucy, you are absolutely right. This must sound like I am all over the place. I am doing my best to apply my steam-powered brain to a higher level of computational efficacy.

Perhaps, with your patience, I can better state my challenge.

I currently have in my .htaccess for following:

RewriteCond %{HTTP_HOST} ^sample1\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sample1\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\/\?post_type\=pbcezmobsite\&p\=2017 " [P]

When I browse to sample1.example I get the page at example/?post_type=pbcezmobsite&p=2017, which is what I intended.

On that page are 5 additional hyperlinks, as follows:


I want these hyperlinks to display as sample1.example.com/p=xxxx where x= the page number from the original file.

example.com/?post_type=pbcezmobsite&p=2040 displays as sample1.example.com/p=2040
example.com/?post_type=pbcezmobsite&p=2041 displays as sample1.example.com/p=2041
example.com/?post_type=pbcezmobsite&p=2059 displays as sample1.example.com/p=2059
example.com/?post_type=pbcezmobsite&p=2069 displays as sample1.example.com/p=2069
example.com/?post_type=pbcezmobsite&p=2071 displays as sample1.example.com/p=2071

I also need to add additional RewriteCond and RewriteRule instances for different web addresses and sets of page numbers.

example.com/?post_type=pbcezmobsite&p=1646 displays as m.example.com/p=1646
example.com/?post_type=pbcezmobsite&p=1662 displays as m.example.com/p=1662
example.com/?post_type=pbcezmobsite&p=1655 displays as m.example.com/p=1655
example.com/?post_type=pbcezmobsite&p=1685 displays as m.example.com/p=1685
example.com/?post_type=pbcezmobsite&p=1687 displays as m.example.com/p=1687

How can I accomplish this with mod_rewrite?

[edited by: engine at 9:04 am (utc) on Apr 17, 2013]
[edit reason] please use example.com [/edit]


 4:05 am on Apr 17, 2013 (gmt 0)

Any suggestions on where I can hire someone to write this rule for me, given that I am not able to figure it out for myself?


 6:01 am on Apr 17, 2013 (gmt 0)

How can I accomplish this with mod_rewrite?

Ouch, ouch. You must have posted this (two days ago) just as I was closing a Forum window, because it somehow slipped under my New Posts radar.

Sit tight for a while longer. My head hurts from unwonted activity in Apache forum so anything I say today will probably be lethally wrong and will bring your site crashing to the ground ;)


 8:26 pm on Apr 17, 2013 (gmt 0)

Now then...
RewriteRule ^/?$ "http\:\/\/example\/\?post_type\=pbcezmobsite\&p\=2017 " [P]

Urk. Let's pick that rule apart.

The /? in the pattern isn't needed. In the config file, patterns begin with a directory slash. In htaccess they don't. So a request for the front page, the root, in htaccess really would be expressed as ^? in a RewriteRule. Or, if you want to be different, !. where both forms mean "nothing" or "empty request".

In the target of a RewriteRule-- the stuff on the right-- nothing needs to be escaped, and quotation marks aren't needed. (They are sometimes appropriate in a RewriteCond.) Most non-alphabetics don't need to be escaped at all, ever. Some Apache mods-- and some other languages-- have to escape slashes because they've got syntactic meaning, but not mod_rewrite. Literal question marks theoretically have to be escaped, but they'll never occur except possibly in a UA string.

Your rule as written has a blank space before the closing quotation mark. Was that a typo in the post? I'd expect it to crash the whole rule. So... Request for root in the two named domains yields

RewriteRule ^$ http://www.example.com/?post_type=pbcezmobsite&p=2017 [P]

:: detour to Apache due to chronic mental block on distinction between [P] and [PT], with further detour as I notice a slightly confusing pair of statements in docs for a (different) flag ::

In your previous post, when you say "displays as..." did you mean "I want it to display as... but it currently displays as something else"?


Is that the actual form of the link, or did you leave something out? You must have done, because as written, links in that form would lead to a browser request for

http://www.example.com/example.com/?post_type et cetera

where "www.example.com" is whichever domain the browser "thinks" it is in (having been fooled by the [P] flag :))

I have to assume the links really say

/?post_type et cetera

The request is then attached to whichever domain the browser currently thinks it is in, and your question is how to conceal the "?post_type=pbcezmobsite&" part.

Matter of fact-- you didn't ask this, but it's an obvious follow-up-- if you're prettifying the URL, do you even need the "p=" element? Seems like what you really want is something like

RewriteCond {same blahblah involving two domain names}
RewriteRule ^(\d\d\d\d)$ http://www.example.com/?post_type=pbcezmobsite&p=$1 [P]

and then, as with any pretty-to-unpretty rewrite, you need the corresponding Redirect for insurance. This goes before all your simple rewrites (with or without [P] flag):

RewriteCond %{THE_REQUEST} \?
RewriteCond {blahblah about one domain name here}
RewriteCond %{QUERY_STRING} (?:post_type=pbcezmobsite&)?p=(\d\d\d\d)
RewriteRule ^$ http://www.example.com/%1? [R=301,L]

You can only capture from one Condition at a time, so you'll need a separate redirect for each domain. This bit is obviously not cut-and-paste; it's a variation of the redirect-to-rewrite two-step. The redirect half is not essential. It's just insurance in case the "real" URL leaks out and gets into someone else's links or bookmarks.

Psst! Moderators! Is there some arcane historical reason why a closing parenthesis after an ampersand turns into a wink?

Wait, n/m, I just figured it out. The ampersand is auto-converted into & ... which creates the ; ) sequence. Since the semicolon in entities is optional, the ampersand carries on happily in its truncated &amp form. D'oh!


 1:14 am on Apr 18, 2013 (gmt 0)

Is there some arcane historical reason why a closing parenthesis after an ampersand turns into a wink?

you can edit your post and click the "Disable graphic smile faces for this post?" checkbox.


 4:30 am on Apr 18, 2013 (gmt 0)

Yes, I know. But then I can't express emotion anywhere else :-P I learned the word-brea
[b][/b]king trick in a php/bb2 forum (doesn't work in /bb3).

You may also have noticed that, just to confuse us, smileys continue to display in Preview; they only disappear in the real thing. And then only until you notice a typo and rush in to edit. Then the option unclicks itself :( The "Disable [codes]" option doesn't seem to want to work for me at all.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved