Forum Moderators: phranque

Message Too Old, No Replies

Internal rewrite question, on subfolder to root and frw. cloak. domain

         

pixeldialog

12:00 pm on May 1, 2009 (gmt 0)

10+ Year Member



Hi.

Newbie to this forum (so hello there) and obviously not a rewrite master either. Have searched and looked around the www for some time now without finding a solution....
Then I found this forum... which seems promising :)

I have the following (names here not real though):

www.test.com
www.test.com/test-index.php

www.test.com/subdir

www.another.com
this domain is forwarded (cloaked) to:
www.test.com/subdir

An internal rewrite (not redirect) is now working if visitor
enter:
www.test.com/subdir
(then the test-index.php on root of www.test.com is run, but enduser still see www.test.com/subdir)

What is not working is this:

(Note: www.another.com is forwarded to:
www.test.com/subdir
using cloaked forwarding)

If I enter:
www.another.com

then I get:

******************************
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@#*$!x.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
*************************

here is .htaccess content in www.test.com/subdir:

############################################
IndexIgnore *
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ /test-index.php?seo=$1
############################################

How can I also make an internal rewrite to the file:
test-index.php
on the root of www.test.com
... if user enter:
www.another.com (which by the way are forwarded to www.test.com/subdir using cloaked forwading)

and make the above work alongside the internal forwarding that now happens if user enter:
www.test.com/subdir?

What I want in the end is this:
if user enter either:
www.test.com/subdir
www.test.com/subdir/somefile

then there should be an internal rewrite so the test-index.php on root of test.com is run.
user should still see what he typed in address field of br.

or

user enter either:
www.another.com
www.another.com/somefile

then there should be an internal rewrite so the test-index.php on root of test.com is run.
user should still see what he typed in address field of br.

Regards

jdMorgan

3:19 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are probably two problems here.

The first problem is that your rule creates an infinite loop.

The second problem is that requests for resources on "another.com" (which resolve to /subdir on the server) may not be able to access files in the root of the server. That depends on how your "add-on domain" was configured.

To fix the first problem, exclude the script path from being rewritten to itself:


RewriteCond $1 !^test-index\.php$
RewriteRule ^(.*)$ /test-index.php?seo=$1 [L]

Jim

pixeldialog

3:49 pm on May 1, 2009 (gmt 0)

10+ Year Member



Jim

Thanks for the answer

I tried:

RewriteCond $1 !^test-index\.php$
RewriteRule ^(.*)$ /test-index.php?seo=$1 [L]

When entering in location of browser:
www.another.com

What happens now is that I no longer get the Internal Server Error 500, which is good...

But then by some reason I'm taken to
www.test.com

in www.test.com (root)
I have this in another .htaccss
ErrorDocument 404 [test.com...]

So now browser location ends up showing
www.test.com
and executing the index.php

Hope it is possible to also get www.another.com
to get an internal rewrite to test-index.php
in www.test.com

Do you have a suggestion on how to fix this?

Thanks for taking the time

Regards

jdMorgan

4:09 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hope it is possible to also get www.another.com
to get an internal rewrite to test-index.php
in www.test.com

It isn't possible to do this using mod_rewrite in most add-on domain set-ups. This is because the root directory of another.com is defined as "/subdir" and not "/".

You may be able to add a symlink (by using a console log-in) from /subdir/index.php to /index.php. If you do not know how to do this, ask your host for assistance. You could also ask you host to install an Alias directive in the server configuration to make index.php appear in both locations, but most host won;t do this.

The basic problem is that most "add-on domain" set-ups are intended to support two (or more) completely-separate sites, and "sharing" programs between the two sites is difficult or impossible. Look into getting a shared hosting account with a unique IP address or a VPS account, which will allow you to point *any* domain to *any place* in your filesystem in any way you choose.

Note also that your ErrorDocument path should have a slash on the end (but this won't fix the problem).

Jim

pixeldialog

7:01 pm on May 1, 2009 (gmt 0)

10+ Year Member



Jim

Thanks a lot for for your quick and very well explanations.

To bad it was not doable the way I was hoping for...
but I will talk to the host and tell them the options I got from you and see if there is a workaround for this stuff.

Another thing that comes to my mind is this:

Basically what I'm after is to have customer specific stuff like images and css files in the subfolders.
And then have the php scripts in one place only (mainly for maintenance reasons (for upgrades of software versions etc))

And then to give the customers options to either use
www.test.com/subdir syntax
or their own domain name if they wish that, like:
www.another.com

If I rented a dedicated server somewhere, would that enable me to to this in a better way, using virtual hosts or something else?

Anyway... thanks a lot so far for your feedback...

Excellent!

jdMorgan

9:14 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need a dedicated server. An account with a unique IP address (called "IP-based virtual hosting") would allow you the flexibility to do this. If you want to spend the money, then a VPS (Virtual Private Server) can be configured to do this. And of course on a dedicated server you can do most anything you like.

It is only at the very-bottom tier, on name-based virtual servers, that this kind of problem arises. In the U.S. you can often upgrade from a name-based virtual server to an IP-based virtual server for $1.00 U.S. per month. That's 12 bucks a year for as many subdomains and domains as you want to host.

Jim

pixeldialog

11:12 am on May 2, 2009 (gmt 0)

10+ Year Member



Thanks again Jim for your answers.

You make this forum shine high above most other forums on the www.

pixeldialog

9:58 am on May 3, 2009 (gmt 0)

10+ Year Member



Hi again

Jim, you said:

"An account with a unique IP address (called "IP-based virtual hosting") would allow you the flexibility to do this."

Will a unique IP address itself solve the issue I had, or do I have do other changes as well, in .htaccess or somewhere else to make it work?

Regards

jdMorgan

9:15 pm on May 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With a unique IP address, you can edit your DNS Zone file, and "point" any domains and subdoamins you like to the IP address of your server. When the request arrives there, most IP-based servers will forward requests for that IP address to your filespace. In your filespace, your .htaccess code can then "sort" the various domain and subdomain requests into different subfolders in any way you like (including handling them all in the same directory -- you're totally free to do anything you like. But since all requests share the same root filespace, then sharing resources (images, scripts, etc.) amoung the various domains and subdomains is no longer a problem.

In the Apache URL Rewriting Guide (see link from mod_rewrite documentation) there is a section called "Mass Virtual Hosting" that discusses one way to do this. The code isn't exactly optimized, but it explains the concept.

So IP-based virtual hosting tends to be the easiest and cheapest solution to hosting multiple domains and subdomains and sharing common elements among them.

Jim

pixeldialog

7:01 am on May 4, 2009 (gmt 0)

10+ Year Member



Hi again...

Jim ... you said:
"With a unique IP address, you can edit your DNS Zone file, and "point" any domains and subdoamins you like to the IP address of your server. When the request arrives there, most IP-based servers will forward requests for that IP address to your filespace."

If I understand you correct then this is the case:

If I have a unique IP address for www.test.com,
then basically all I have to do is to make www.another.com forward to the IP address instead of [test.com...]

Is it possible to forward directly to the subdir of the IP address somehow, and then keep the rewrite code in the .htaccess of the subdir of www.test.com,

or do I have to forward to the root of www.test.com and then use one .htaccess for handling all the subdirectories?
(I hope I can avoid the last one though)...

Thanks again for ultraquick replies

Regards