Forum Moderators: phranque

Message Too Old, No Replies

subdomain to same domain url

can't quite wrap my mind around it

         

pjf5000

7:02 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



All requests to sub.domain.com need to be rewritten to sub.domain.com/url/*

However, I don't want it to rewrite if the URI is already sub.domain.com/url

to make it more interesting /url is handled by Drupal, so I can't just create a empty url folder and put the .htaccess in there.

Any help would be greatly appreciated.

Thanks in advance.

g1smd

7:43 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you already tried?

There is also example code in several threads here from the last few weeks.

pjf5000

9:23 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



RewriteCond %{HTTP_HOST} ^sub-one\.domain\.com [NC]
RewriteRule [sub-one.domain.com...] [R=301,L]

it doesn't seem to be catching the rule.

I looked through about 20 other posts, and haven't quite found the answer.

Thanks for your help.

g1smd

10:05 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You asked for a rewrite.

The RewriteRule needs two components: the requested URL (without domain and leading / here), and the server filepath of where the content is (without the domain included).

You are missing the requested URL, you'll need a (.*) on the left for that.

For a rewrite, the target should be a server filepath, so you should NOT include the http or the domain.

You asked for a rewrite, but you have included a [R=301] in the code. That is a redirect, not a rewrite.

You'll also need to test whether the rewrite is invoked by adding a RewriteCond like this:
RewriteCond %{REQUEST_URI} !(.*)url

.

A rewrite fetches content from somewhere inside the server that is hidden from the user.

A redirect forces the browser to visit a new URL. That is what the [R=301] does.

pjf5000

10:50 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



thanks for your reply.

Here is what I have at the moment:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub-one\.domain\.com [NC]
RewriteCond %{REQUEST_URI}!(.*)url
RewriteRule (.*) [sub-one.domain.com...]

It won't load now, but it hits the rule, I end up with:

[sub-one.domain.com...] ect etc

I asked for a rewrite because I'm not sure a redirect will do it.

[sub-one.domain.com...] is generated by the application (drupal)
there is no actual url file or directory on the filesystem, does that make sense?

I'm wondering if what I'm trying to accomplish is even possible like this.

Thanks again.

g1smd

11:12 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I really do need to nail whether you need a redirect (where the URL in browser changes), or a rewrite (where the URL does not change but the server pulls content from some other place on the server, a place that is hidden from the user).

When you say drupal generates URLs like "that", do you mean that it puts links in that format on the content pages, or do you mean that it responds to URL requests in that format?

pjf5000

11:29 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



A rewrite, we want the URL in the browser to remain the same, it should show:

[sub-one.domain.com...] but actually send [sub-one.domain.com...] to the server

I mean it responds to URL requests in THAT format, if you type in [sub-one.domain.com...] it shows the specific content.

it even confuses me when I try and explain it :>

jdMorgan

12:34 am on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am seriously considering banning the use of the word "it" in this thread. Using the word "it" more than once per sentence is far too ambiguous in these kinds of discussions. :)

The browser will display the same URL it sends to the server, and security considerations mean that there is nothing the server can change about that browser behaviour.

I'm going to guess that what you are struggling for is something like this:


RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^sub-one\.domain\.com [NC]
RewriteCond $1 !^url/
RewriteRule (.*) /url/$1 [L]

If you still get a loop let us know, as this could be caused by an interaction between drupal and your .htaccess code.

Jim

[edited by: jdMorgan at 12:35 am (utc) on Sep. 6, 2007]

pjf5000

4:40 am on Sep 6, 2007 (gmt 0)

10+ Year Member



thanks a bunch both of you.

I'm still getting a loop though, now I get the following in the browser URL location:

[sub-one.domain.com...]

is it clashing with the internal drupal redirect?

g1smd

1:20 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Very probably. That might need a conditional test added to it too.