homepage Welcome to WebmasterWorld Guest from 23.20.44.136
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Frustrations and .htaccess
.htaccess yet again..
ozgreg




msg:1512679
 3:26 pm on Oct 6, 2003 (gmt 0)

Hiya all,

Ok the usual issue we have seen it alll before create an subdomain and it creates a folder in root and automatically redirects the subdomain to that folder.

Except this time I DO NOT want the subdomain.domain.com to redirect to the folder instead IT MUST go to the root directory.

IE: Cpanel Server subdomain "demo.domain.com" translates to /home/account/www/demo I need it to translate to /home/account/www/

adding an .htaccess Redirect Permanent / [domain.com...] in /demo will redirect the browser to / but the URI is still /demo and I need the URI to really be /

I tried this but basically I cannot get it to work.

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} demo.domain.com
RewriteCond %{REQUEST_URI}!/
RewriteRule ^(.*)$ /$1 [L]

Am I on the right track? Or completely off base..

Help please, can someone suggest a solution... I am way out of my depth here and unsure how to proceed.

 

jdMorgan




msg:1512680
 3:51 pm on Oct 6, 2003 (gmt 0)

ozgreg,

Welcome to WebmasterWorld [webmasterworld.com]!

Options must precede RewriteEngine on.
Your first RewriteCond contains unescaped literal periods, and is unanchored.
Your second RewriteCond will prevent anything starting with demo.domain.com/ from being redirected.
(Perhaps you intended to prevent redirecting only "demo.domain.com/", in which case you need an end anchor. If you do not wish to prevent redirecting "/" delete that line.)
Your RewriteRule specifies an internal (silent) redirect -- it will not update the URL. If you wish to update the URL in the user's browser address bar, you need to use a 301 or 302 redirect:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^demo\.domain\.com
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1 [R=301,L]

I suggest you read this Introduction to mod_rewrite [webmasterworld.com] thread, and follow the links to the Apache mod_rewrite documentation and the regular expressions tutorial.

Jim

ozgreg




msg:1512681
 11:41 pm on Oct 6, 2003 (gmt 0)

Thanks JD but unfortunately I did not get the result I am looking for as it basically ignores the

RewriteCond %{HTTP_HOST} ^demo\.domain\.com
RewriteCond %{REQUEST_URI}!/$

Specified in the .htaccess at root and continues to dump me still in /demo directory which is NOT desired.

I cannot think of any other way to stop being dumped in the \demo directory, can you?

jdMorgan




msg:1512682
 12:55 am on Oct 7, 2003 (gmt 0)

Yes,

It's not ignoring it, it's probably just not executing it.

Put the .htaccess code in the demo directory itself. It cannot do anything if it is not activated, so it has to be placed wherever requests to that demo.domain.com domain "land" in your directory structure.

There are a million ways to configure subdomains and subdirectories, but I think I understand your goal. So this should work if it gets activated.

Jim

Monus




msg:1512683
 1:20 am on Oct 7, 2003 (gmt 0)

Have you been trying this.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^demo.domain.com$
RewriteCond %{REQUEST_URI}!^/demo/
RewriteRule (.*) /demo/$1

It's working on my site.

ozgreg




msg:1512684
 6:59 am on Oct 14, 2003 (gmt 0)

Firstly thankyou all for helping and yes, you are totally correct it ignores the root .htaccess and instead executes the .htaccess in the subdirectory that is "associated with the domain" ie dorm.domain.com is linked to domain.com/dorm

Unfortunately this fundermentally breaks the concept of subdomain CMS in NukeHall although I can do a redirect

RewriteEngine on
RewriteCond %{HTTP_HOST} ^dorm.domain.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.dorm.domain.org$
RewriteRule ^(.*)$ [domain.org...] [R=301,L]

The cookies generated are incorrect because URL is www.domain.org rather than dorm.domain.org thus I am pretty fundermentally stuffed.

Since my hands are tied and the webserver is going to dump me in to the \dorm subdirectory how can get apache to instead point to the root directory without having to do a 30x redirection?

jdMorgan




msg:1512685
 12:23 am on Oct 16, 2003 (gmt 0)

ozgreg,

> Since my hands are tied and the webserver is going to dump me in to the \dorm subdirectory how can get apache to instead point to the root directory without having to do a 30x redirection?

By putting the code in /dorm/.htaccess instead of in your web root.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?dorm.domain.org$
RewriteRule ^(.*)$ http://www.domain.org/$1 [R=301,L]

> The cookies generated are incorrect because URL is www.domain.org rather than dorm.domain.org thus I am pretty fundermentally stuffed.

Don't set any cookies until the domain stuff is sorted. Cookies will only be valid for the domain in which they are set.

> Since my hands are tied and the webserver is going to dump me in to the \dorm subdirectory how can get apache to instead point to the root directory without having to do a 30x redirection?

I don't think you can, unless "/" resolves to your web root directory.

You can try:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?dorm.domain.org$
RewriteRule ^(.*)$ /$1 [L]

but I'm not sure if that will work. If it does not work, it may put the server into a loop, so be careful.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved