Forum Moderators: phranque

Message Too Old, No Replies

Using Subdirectory as subdomain in htaccess

subdirectory as subdomain

         

khalidhydro

9:51 pm on May 31, 2012 (gmt 0)

10+ Year Member



I am trying to point a subfolder on my site as a subdomain. for example, i want to turn www.domain.com/test to test.domain.com. I already have some rewrites in htaccess done by developers that we used earlier in the site building process, and I'd like to be able to add this line without interfering with those.

I've tried dozens of answers to this issue i found across the net, but none of them seemed to work and i'm not sure if it's due to my lack of knowledge of this language or if there's a conflict with something else.

The latest lines I tried are:

RewriteCond %{HTTP_HOST} !^www.domain.tv
RewriteCond %{HTTP_HOST} ([^.]+).domain.tv
RewriteRule ^(.*)$ /var/www/www.domain.tv/test%1
This is my current htaccess file:

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

#RewriteCond %{HTTP_HOST} !www\.domain\.tv$ [NC]
#RewriteCond %{HTTP_HOST} ^(.+)\.domain\.tv$ [NC]
#RewriteRule .* index.php?option=com_contushdvideoshare&view=player&Itemid=33 [L]

RewriteCond %{REQUEST_URI} ^/album\/t\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/t/(.*) index.php?option=com_usermenu&task=directdownload&id=$1&type=one$

RewriteCond %{REQUEST_URI} ^/album\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/(.*) index.php?option=com_usermenu&task=directdownload&id=$1 [L]


RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]

#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Can anyone help me here?

g1smd

10:17 pm on May 31, 2012 (gmt 0)

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



You'll need DNS to link requests for the subdomain to the folder where the site will reside. Without the appropriate DNS entry the requests aren't even resolving to your server.

Then you'll need a redirect in the root of www that looks for requests for example.com/subdomain and www.example.com/subdomain and redirects them to make a new request for subdomain.example.com


Beyond that, there are a large number of errors in your code, not limited to missing escaping, unecessary escaping, rules in the wrong order, inefficient RegEx patterns and missing status flags.

khalidhydro

10:38 pm on May 31, 2012 (gmt 0)

10+ Year Member



Could you explain the DNS statement? Does it need it's own IP? Also, would those redirects need to be made in htaccess?

lucy24

11:05 pm on May 31, 2012 (gmt 0)

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



If it's your own server, put everything in the config file. If not, you've no choice but to use htaccess.

If you're on shared hosting, you may need to talk to the host about setting up a subdomain. Otherwise talk to your existing domain's registrar. The subdomain does not need a separate IP, just a physical location. You've got that part.

incrediBILL

11:15 pm on May 31, 2012 (gmt 0)

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



If it's a shared server it's most likely it's aomething easily accomplished on the control panel which most have. Even on a dedicated server, I use a control panel just to avoid such hassles. Adding a subdomain is a simple task with a couple of clicks and then adding a DNS entry and it's complete.

Regardless of whether you use a control panel or roll your own Apache config, you still need a CNAME record added to your DNS to make it all work. You would need to add a record for "subdomain.example.com" of the type CNAME that resolves to the target "example.com" or the IP address.

khalidhydro

11:32 pm on May 31, 2012 (gmt 0)

10+ Year Member



@lucy, it is our own server, being that it's a rackspace hosted cloud server that i have root shell access to. Which config file would i put everything into?

@incrediBILL, I don't have a control panel, that would be AWESOME. it's either shell access or nothing. There is a control panel as far as DNS stuff goes, but that's about it.

Turns out there is also a htaccess file in the folder i'm trying to make as a subdomain, so i think i might need to create a different folder for this use.

This is that htaccess file:

Options +FollowSymLinks

RewriteEngine On

RewriteBase /dev

#RewriteCond %{HTTP_HOST} !lc\.domain\.tv$ [NC]
#RewriteCond %{HTTP_HOST} ^(.+)\.domain\.tv$ [NC]
#RewriteRule .* index.php?option=com_contushdvideoshare&view=player&Itemid=33 [L]

RewriteCond %{REQUEST_URI} ^/dev/album\/t\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/t/(.*) index.php?option=com_usermenu&task=directdownload&id=$1&type=onetime [L]

RewriteCond %{REQUEST_URI} ^/dev/album\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/(.*) index.php?option=com_usermenu&task=directdownload&id=$1 [L]


RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]

#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


RewriteCond %{REQUEST_URI} !^/dev/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]


So i think maybe if i start with a fresh folder, with a blank htaccess perhaps i can have an easier time trying to do this. sorry i'm such a noob with all this