Forum Moderators: phranque

Message Too Old, No Replies

redirect subdomain to subfolder

         

gsgruppen

2:33 pm on Sep 3, 2012 (gmt 0)

10+ Year Member



Dear all

It seem that not all browsers work the same way for redirecting in .htaccess

We have a working Joomla on main domain. www.domain.net
So I created a subdomain: www.sub.domain.net - and installed at new GNU account-system there. All parts is located in a subfolder in this subdomain - for this GNU system, but this system require some system PHP parameters to be changed - so I have a .htaccess file there for doing this at www.sub.domain.net level.
At serverside this looks like this:
/account
.htaccess

I also had a index.php for html redirect - but that I can't make work - so I deleted this :-(

In the subfolder "account" the whole system is placed and it also include index.php and another .htaccess file - with no redict, only:

# Set the default index.
DirectoryIndex index.php
)

Without interfering with the www.domain.net - with is actually redirected to www.domain.org - I will like to have ALL requests (which are coming from many places and setup) to anything in www.sub.domain.net redirected to the subfolder and get connected to the index.php file there.

This include requests like
* sub.domain.net
* www.sub.domain.net
* sub.domain.net/index.php
* www.sub.domain.net/index.php
* sub.domain.net/index.html
* www.sub.domain.net/index.html

And surely direct request to the subfolder should also work:
* www.sub.domain.net/account
* www.sub.domain.net/account/index.php
* www.sub.domain.net/account/index.html

I simply can make all work - testing in IE, firefox and Chrome.
I had a few of them working, in some browsers - but else it seem to loop or just can't find anything - and sometime the URL in browser duplicate the last part of the URL many times - giving an error.

Can anyone help with a .htaccess file for root folder for subdomain
and some directions if needed for .htaccess in subfolder.

I really don't get it after trying many things :-(

There are 2 redirection created in controlpanel
* www.sub.domain.net/index.php=www.sub.domain.net/account/index.php
* www.sub.domain.net/index.html=www.sub.domain.net/account/index.php

I will like to start all over again - and have therefore deleate the trial I got from this forum.

g1smd

2:46 pm on Sep 3, 2012 (gmt 0)

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



All browsers do work the same for redirects. A redirect is a redirect.

Redirect status is cacheable so you must clear cache before retesting.

The Live HTTP Headers extension for Firefox will tell you what is going on.

It sounds like your RegEx pattern for redirecting also matches the new URL, rematches it and redirects again.

gsgruppen

3:02 pm on Sep 3, 2012 (gmt 0)

10+ Year Member



Hi g1smd

Okey - the cache thing - I knew!
Do you have a suggestion for .htaccess?

g1smd

3:51 pm on Sep 3, 2012 (gmt 0)

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



This topic comes up several times each week, so I've already participated in several hundred previous threads discussing what to do. Many of those have detailed code examples. Your first port of call has to be to read some of those, borrow code, test it, then report back here with specific problems encountered, along with the actual code excerpt. We don't write code for you. We help you to get your code working.

lucy24

8:33 pm on Sep 3, 2012 (gmt 0)

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



And surely direct request to the subfolder should also work:
* www.sub.domain.net/account
* www.sub.domain.net/account/index.php
* www.sub.domain.net/account/index.html

NOOOO. Requests for your named index file

www.example.com/blahblah/index.php

should be redirected to the proper form of the directory name, which is simply

www.example.com/blahblah/

Requests for names you don't actually use, such as index.html, are properly served with a 404. (In my case requests for index.php get a 403, because I have no php content outside of piwik, so a request for anything.php is the mark of the unwanted robot.) The only exception is if some dimwitted but desirable site has linked to you with an incorrect name. Then you may want to direct those specific files to the right one.

Conversely, requests for

www.example.com/directory

without trailing slash don't need any further action if the directory really exists. mod_dir will take care of it. You only need htaccess if it's a fake directory created for SEO purposes.

I will like to have ALL requests (which are coming from many places and setup) to anything in www.sub.domain.net redirected to the subfolder and get connected to the index.php file there

Please say you don't mean that all requests for any page in a particular (sub)domain should all get redirected to the same page. Or do you mean the generic pattern of

www.example.net/someURL >> www.example.com/someURL

? What happens to requests for non-directory-index pages?

gsgruppen

5:40 am on Sep 4, 2012 (gmt 0)

10+ Year Member



Lucy24 - thanks very much - your explanation have been very very helpful and now everything works perfectly and more important I also now understand much better the idea - how it works.

I'm sure many other can and will use this :-)

Thanks...