Forum Moderators: phranque

Message Too Old, No Replies

HELP! mod rewrite subdomain to page on root domain

         

jbgilbert

9:07 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



I'm not good at this stuff, so I'll provide specifics in hopes of finding some help with a working example.

I need all requests for [subdomain.ortz.com...] to get permanently redirected to a page on the root domain (http://www.ortz.com/thepage.html).

I also need for the address bar in the browser to show [subdomain.ortz.com...] following the redirection.

Can somebody please show me what the .htaccess file on Apache should be to make this happen?

Also, will the .htaccess file have to go in the root or in the subdomain folder?

qqq

jdMorgan

11:45 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See RewriteCond in mod_rewrite [httpd.apache.org]. Use

RewriteCond %{HTTP_HOST} ^subdomain_name\.

as a condition on a RewriteRule that rewrites -- not redirects -- to the file you want served.

You can place the code in .htaccess in either the subfolder or in root *if* all subdomains resolve directly to root. Otherwise, the code will need to go into the subfolder, which will be less efficient. The pattern used in the RewriteRule will need to be adjusted to reflect the code's location.

Please see the references cited in our forum charter for more information, as well as our forum policies.

Jim

jbgilbert

4:14 pm on Nov 18, 2004 (gmt 0)

10+ Year Member



jd.. thanks for the response. I'll try this this afternoon and get back to you.

I have searched the forum, but still not finding anything that leaves the subdomain address in the address bar after the rewrite.

Hope your example does the trick.

jdMorgan

5:10 pm on Nov 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Rewrite" and "redirect" are two very different functions in mod_rewrite. A RewriteRule for a redirect contains a canoncial URL and an [R] flag, and redirects the client browser (thus changing the URL in the address bar), while a RewriteRule for an internal rewrite contains only a local URL-path.

A redirect requires the cooperation of the client browser: The server sends a 301 or 302 response telling the browser to re-request the desired resource and gives it the new URL. The browser then must issue a new HTTP request using the new URL to get the relocated content.

A rewrite simply changes the "file" that a URL corresponds to. The client is unaware of this change.

Key in on those differences, and the examples will be more useful.

Jim