Welcome to WebmasterWorld Guest from 54.162.227.136

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Frustrations and .htaccess

.htaccess yet again..

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

10+ Year Member



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.

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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?

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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.

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

10+ Year Member



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?

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month