GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   htaccess subdomain & non-www to www redirects. (https://gfy.com/showthread.php?t=868721)

nico-t 11-12-2008 07:16 AM

htaccess subdomain & non-www to www redirects.
 
They seem to interfere with eachother, the non-www to www redirect overwrites the subdomain to subdir redirect so subdomains just go to www.mydomain.com without subdir.

Let me explain the situation, i have subdomains i want to their respective subdir.
So
title.mydomain.com to www.mydomain.com/title/
titletwo.mydomain.com to www.mydomain.com/titletwo/
etc.
But right now i also have the non-www to www redirect code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

But when i add this subdomain to subdir code to the htaccess (which redirects all subdomains to subdirs except when it's www):

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com [NC]
RewriteRule (.*) http://www.mydomain.com/%1/$1 [R=301,L]


.... it just redirects the subdomains to the home page www.mydomain.com.
How do i do this?

Brujah 11-12-2008 07:19 AM

Try this maybe:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com [NC]
RewriteRule (.*) http://www.mydomain.com/%1/$1 [R=301,L]

nico-t 11-12-2008 07:24 AM

no that doesnt make a difference

Voodoo 11-12-2008 07:27 AM

EDIT:
Nevermind

Antonio 11-12-2008 07:39 AM

not 100% sure but you might need to have wildcard domains enabled on the host?

I know wordpress MU (for multiple blogs on subdomains) won't work unless the host has wildcard domains enabled

anyway, just a guess

Brujah 11-12-2008 08:09 AM

Tested this on mine, so far it worked. Maybe you can mix it up from here.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %1 !^(www)$ [NC]
RewriteRule ^$ /%1/$1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

nico-t 11-12-2008 08:30 AM

Thanks for the effort, but that doesnt work at all doesnt even redirect to the main domain

Let me show you how the htaccess looks:

Code:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %1 !^(www)$ [NC]
RewriteRule ^$ /%1/$1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

And antonio i dont know what you mean


edited a bit

nico-t 11-12-2008 08:46 AM

hm i have an idea.. will test it later and report if it worked. Now im having a break

fris 11-12-2008 09:29 AM

i tested it and it works, so dont say it doesnt :p

Code:

Options +FollowSymLinks
RewriteEngine On

# force www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

# abc.domain.com/def --> /subs/abc/def
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subs/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ http://%2.domain.com%{REQUEST_URI}/ [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /subs/%1/$1 [QSA,L]


nico-t 11-12-2008 11:15 AM

well thanks but it doesnt work for me..... gonna email my host.

fris 11-12-2008 11:16 AM

bump for nico-t if he didnt get it

nico-t 11-12-2008 12:51 PM

no luck for me fris i see we posted at same time anyway i emailed my host usually they are pretty fast with solving any issues.... ill post here what it is once i get a reply...


All times are GMT -7. The time now is 03:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123