Forum Moderators: phranque

Message Too Old, No Replies

Use .htaccess to make a subdomain appear as the root

How can I get /forums/index.html to appear as /index.html

         

cscgal

10:21 pm on Jul 15, 2003 (gmt 0)

10+ Year Member



My entire site (for the most part) is contained in a /forums/ subdirectory: [mydomain.com...]

Because just about every page is in this directory, I'd like to use .htaccess mod_rewrite to make this directory appear as the root.

For example, a page located at [mydomain.com...] would be accessible from [mydomain.com...]

Similarly, a page located at [mydomain.com...] would be accessible from [mydomain.com...]

Can anyone tell me exactly what I need to place in .htaccess to be able to do this?

Thanks!

[edited by: DaveAtIFG at 11:41 pm (utc) on July 15, 2003]
[edit reason] "Generalized" specific URLs [/edit]

moltar

10:28 pm on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i think:

RewriteEngine On
RewriteRule ^(.*)$ /forum/$1

cscgal

11:44 pm on Jul 15, 2003 (gmt 0)

10+ Year Member



That worked, thanks. Unfortunately, I tried it and can't use it. I use an /index.cgi file to redirect subdomains to appropriate pages, and this .htaccess command makes it so that my subdomains no longer work. :(

jdMorgan

9:08 pm on Jul 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cscgal,

Welcome to WebmasterWorld [webmasterworld.com]!

You will need a RewriteCond to exclude your subdomains from being rewritten:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^(.*)$ /forum/$1 [L]

This code requires that the requested domain be "www.mydomain.com", "mydomain.com" or uppercase variations of the same. Otherwise, the rule will not be applied. Therefore, subdomains other than "www" will not be rewritten.

Ref: Introduction to mod_rewrite [webmasterworld.com]

HTH,
Jim

cscgal

9:21 pm on Jul 16, 2003 (gmt 0)

10+ Year Member



oooh thanks! :)