LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-03-2014, 01:37 PM   #1
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
Apache / wildcard DNS / vhost question


I am reorganizing the way I do development and rather than create one virtualhost per project I want to use a wildcard DNS and virtualhost.

I have a directory called dev and test. I want to make it so if I type

*.d.server.loc (.d. for dev, .t. for test)

It goes to dev/* folder.

So say I have a folder called project1 in dev I want to type project1.d.server.loc and it will go to that folder.

I already have the wildcard DNS setup. I'm guessing in apache this may be doable with mod rewrite. How would it be done, if possible?
 
Old 07-04-2014, 03:11 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Yes, you can use mod_rewrite, like this:
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(.+).d.server.loc$
RewriteRule (.*) http://d.server.loc/dev/%1
Regards
 
Old 07-04-2014, 06:54 AM   #3
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
Quote:
Originally Posted by bathory View Post
Yes, you can use mod_rewrite, like this:
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(.+).d.server.loc$
RewriteRule (.*) http://d.server.loc/dev/%1
Regards
Thanks, could you show me a full example including the virtualhost block, just not sure exactly where/how to use that. I'm guessing there are variables I need to put in there as well.
 
Old 07-04-2014, 08:31 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Thanks, could you show me a full example including the virtualhost block, just not sure exactly where/how to use that. I'm guessing there are variables I need to put in there as well.
There is nothing fancy:
Code:
<VirtualHost *:80>
 DocumentRoot /var/www/html
 ServerName d.server.loc
 ServerAlias *.d.server.loc

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(.+).d.server.loc$
RewriteRule (.*) http://d.server.loc/dev/%1

...
</VirtualHost>
Just change the docroot accordingly.
 
Old 07-04-2014, 12:09 PM   #5
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
Hmmm so it's basically just a redirect? I got it working but I'll have to test further. If a site refers to / (ex: to refer to the css file) I'm not sure if that will work.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Internal Server Redirection vhost => vhost not working [Debian & Apache 2] Smokin... Linux - Server 1 05-26-2013 12:06 PM
DNS wildcard help conflicker Linux - Newbie 3 02-07-2012 10:56 AM
vhost configuration for CNAME wildcard subdomains leif_84 Linux - Server 1 01-08-2008 02:13 AM
How to setup wildcard DNS RAHUKUMAR Linux - Software 3 11-23-2005 01:02 PM
Apache: Alias is working on ssl vhost but not on mass vhost jonavogt Linux - Software 0 06-07-2005 02:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration