LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-18-2012, 02:34 PM   #1
conflicker
Member
 
Registered: Sep 2011
Posts: 88

Rep: Reputation: Disabled
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
 
Old 07-18-2012, 03:09 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,563

Rep: Reputation: 410Reputation: 410Reputation: 410Reputation: 410Reputation: 410
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.
 
Old 07-18-2012, 05:34 PM   #3
conflicker
Member
 
Registered: Sep 2011
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Kustom42 View Post
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..
 
Old 07-18-2012, 05:51 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,563

Rep: Reputation: 410Reputation: 410Reputation: 410Reputation: 410Reputation: 410
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/
 
Old 07-18-2012, 06:09 PM   #5
conflicker
Member
 
Registered: Sep 2011
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Kustom42 View Post
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?
 
Old 07-18-2012, 06:18 PM   #6
conflicker
Member
 
Registered: Sep 2011
Posts: 88

Original Poster
Rep: Reputation: Disabled
[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/
 
Old 07-18-2012, 06:23 PM   #7
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by Kustom42 View Post
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
 
Old 07-18-2012, 06:23 PM   #8
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,563

Rep: Reputation: 410Reputation: 410Reputation: 410Reputation: 410Reputation: 410
Yep that'll do it..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache no-www to www domain rewrite after upgrade deesto Linux - Server 5 06-20-2012 12:16 PM
Setup sample SSL subdomain site but keeps going to www j.smith1981 Linux - Server 14 02-03-2012 05:14 AM
DNS http:domain.com resolve to www.domain.com keysorsoze Linux - Networking 3 02-12-2007 03:03 AM
Cant get entry in bind to work with domain.com instead of www.domain.com pxes351 Linux - Networking 12 05-09-2005 06:20 AM


All times are GMT -5. The time now is 02:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration