Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule to go up a directory

trying to get an htaccess file to do an internal redirect to higher directo

         

krioukov

6:56 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



Hello!

Here is my situation I have two domain names hosted on one web server.

The primary domain aaa.com is located in
/home/me/public_html/

I also have a second domain which is an "add-on domain" (ie virtual host). It is located in a subdirectory:
/home/me/public_html/domaintwo

Now what I wanted to do was create a subdomain for domaintwo (sub.domaintwo.com) so i used my CPanel config to do this BUT my server is stupid and put the subdomain in
/home/me/public_html/sub
(But yes i can access it by going to sub.domaintwo.com)

Of course I wanted it in
/home/me/public_html/domaintwo/sub
(becuase it is a subdomain of domaintwo)

I cannot get my server admin to change this so I have to fix it with an htaccess file.

--------------
Here is what i tried:

1) First I put an htaccess in /home/me/public_html/sub
it looked like this:


RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^sub\.domaintwo\.com$
RewriteRule (.*) ../domaintwo/sub/$1

Unfortuately I get a "Invalid URI in request GET / HTTP/1.1" error. I assume i can't put ".." in the rewrite.

2)Next I tried to put an htaccess in my primary domains root - /home/me/public_html/


RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^sub\.domaintwo\.com$
RewriteRule (.*) /domaintwo/sub/$1 [L]

This did not work either: I got an Internal Server Error (and no new info in error logs).

3) Finally I tried putting an htaccess in /home/me/public_html/domaintwo/


RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^sub\.domaintwo\.com$
RewriteCond %{REQUEST_URI}!^/sub/
RewriteRule (.*) /sub/$1

This had no effect at all... I just got the directory listing of /home/me/public_html/sub

So now Im all out of ideas... If you know what i'm doing wrong please tell me :)

Thank you very much,
Andrew Krioukov

jdMorgan

1:09 am on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Andrew,

Welcome to WebmasterWorld [webmasterworld.com]!

Case 1 did not work because "../" is not valid in a server context - It has meaning only to a browser or to a shell command. The reason it is not supported in a server context is that it leads to too many security problems.

It is possible that case 2 did not work because your host is set up to disallow rewrites in the public_html directory in order to avoid conflicts with the code that cPanel generates.

Case 3 won't work because the .htaccess file is not in the directory path used to resolve the subdomain, as specified by the cPanel code.

You could try this in /sub


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domaintwo\.com
RewriteRule (.*) /domaintwo/sub/$1 [L]

If a request for "/" will resolve to public_html, then "/domaintwo/sub/" should resolve to the subdirectory you want to use. Beginning a URL substitution with "/" basically tells the server to go to the top HTTP-accessible directory, and resolve the given URL from that point down.

Note that I removed the end-anchor from the hostname pattern: This is necessary to support proxies which add the server port number to the hostname, i.e. sub.domain.com:80

Jim

krioukov

11:24 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



Thanks for the suggestion, but when I tried what you told me to do I got a 505 error with no info in the log.

I figured out that the error occurs only when I fill in the real values of sub and domaintwo in this line:
RewriteCond %{HTTP_HOST} ^sub\.domaintwo\.com

So i guess all that means is that it is not a syntax error its something that happens only when we try to redirect. Could it be that absolute paths (starting from root '/') are not allowed on my server?

Also do you have any other suggestions?

jdMorgan

11:58 pm on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A 505 error - strange!

505 HTTP Version Not Supported

The server does not support, or refuses to support, the HTTP protocol version that was used in the request message. The server is indicating that it is unable or unwilling to complete the request using the same major version as the client other than with this error message. The response SHOULD contain an entity describing why that version is not supported and what other protocols are supported by that server.

Jim