LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   .htaccess redirect non-existent directory to subdomain (https://www.linuxquestions.org/questions/linux-server-73/htaccess-redirect-non-existent-directory-to-subdomain-868133/)

PlymWS 03-12-2011 09:26 AM

.htaccess redirect non-existent directory to subdomain
 
Hi,

Im reorganising my web diretory because it's become messy. I've changed the structure of things so that folders below root are now subdomains e.g. http://domain.com/forums will now be at http://forums.domain.com.

What I want to do is put a .htaccess redirect in place so that requests for the forums diretcory get routed to the subdomain. However the answers I've found on Google aren't working.

The new directory structure is like this :

Root
-Main
-Subdomains
--Forums
--Sub2

The domain is setup so that the directory "Main" is its root and that works fine. The problem is that trying to goto /forums 404s because the directory doesn't exist.

Ideally I would like to have any request for a directory below root to be redirected to the subdomain directory automatically so I can add subdomain directories and they will automatically work if the directory exists.

timetraveler 03-12-2011 10:56 AM

Since you have control of the server you should not use .htaccess.
Have a look at the rewrite module. It will let you do what you want.
Try some things and let us know if isn't working.

bathory 03-12-2011 11:19 AM

Hi,

If you have a couple of URLs that you want to redirect to subdomains according the requested URI, you can use:
Code:

Redirect /forums http://forums.domain.com
Of more redirects, you can use wildcards with mod_rewrite as mentioned by the previous poster

Regards


All times are GMT -5. The time now is 03:59 AM.