LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   htaccess remove www for subdomain and add www for main domain (http://www.linuxquestions.org/questions/programming-9/htaccess-remove-www-for-subdomain-and-add-www-for-main-domain-4175417442/)

conflicker 07-18-2012 02:34 PM

htaccess remove www for subdomain and add www for main domain
 
Hi, anyone has the idea of some htaccess script the remove the www for subdomain like
I want to remove the www in front of and at the same time add www for main domain like
Quote:

maindomain.com
Any help would much be appreciated.

Thanks

Kustom42 07-18-2012 03:09 PM

Do a google search for .htaccess rewrite generator... Easy peasy just tell it what you want to rewrite and it spits out the code for you.

conflicker 07-18-2012 05:34 PM

Quote:

Originally Posted by Kustom42 (Post 4731964)
Do a google search for .htaccess rewrite generator... Easy peasy just tell it what you want to rewrite and it spits out the code for you.

Most of the generator is for formatting the url, I can't find a way to determine if the url has subdomain..

Kustom42 07-18-2012 05:51 PM

Code:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.test\.maindomain\.com
RewriteRule .* http://test.maindomain.com/ [L]
RewriteCond %{HTTP_HOST} ^maindomain\.com
RewriteRule .* http;//www.maindomain.com/


conflicker 07-18-2012 06:09 PM

Quote:

Originally Posted by Kustom42 (Post 4732091)
Code:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.test\.maindomain\.com
RewriteRule .* http://test.maindomain.com/ [L]
RewriteCond %{HTTP_HOST} ^maindomain\.com
RewriteRule .* http;//www.maindomain.com/


How can I make the subdomain dynamic?

conflicker 07-18-2012 06:18 PM

[QUOTE=Kustom42;4732091][CODE]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.test\.maindomain\.com
RewriteRule .* http://test.maindomain.com/ [L]
RewriteCond %{HTTP_HOST} ^maindomain\.com
RewriteRule .* http;//www.maindomain.com/

I already got it, Thanks for the help here is my final script:
Quote:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)\.maindomain\.com
RewriteRule .* http://%1.maindomain.com/ [L]
RewriteCond %{HTTP_HOST} ^maindomain\.com
RewriteRule .* http://www.maindomain.com/

lithos 07-18-2012 06:23 PM

Quote:

Originally Posted by Kustom42 (Post 4732091)
Code:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.test\.maindomain\.com
RewriteRule .* http://test.maindomain.com/ [L]
RewriteCond %{HTTP_HOST} ^maindomain\.com
RewriteRule .* http;//www.maindomain.com/


Hi,
sorry I don't really know how, just seen there a typo
";" should be ":"

good luck

Kustom42 07-18-2012 06:23 PM

Yep that'll do it..


All times are GMT -5. The time now is 08:40 AM.