Jump to content
Sign in to follow this  
Balderick

redirect not existing subdomain to www with htaccess

Recommended Posts

I'm looking for directives that help solving the problem of redirecting a not existing subdomain towards the www subdomain.

 

I know/guess .htaccess is used, but cant figure out how.

 

My present situation is that existing subdomains are redirected well.

 

I adjusted virtual hosts in this way:

       <VirtualHost *:80> 
		ServerName mysite.dev
		ServerAlias mysite.dev *.mysite.dev
		DocumentRoot X:/wamp/www/TestVirtHost/
		<Directory  "X:/wamp/www/TestVirtHost/">
			Options +Indexes +FollowSymLinks +MultiViews
			AllowOverride All
			Require local
		</Directory>
	</VirtualHost>

my etc/hosts file has the following rules

     127.0.0.1  *.mysite.dev mysite.dev
     127.0.0.1 subdomain_one.mysite.dev
     127.0.0.1 subdomain_two.mysite.dev

Can some expert explain please what the .htaccess should look like for the problem explained above.

Share this post


Link to post
Share on other sites

I think you would only be able to do that if you have subdomains mapping to specific directories, and you can use htaccess to check if the directory exists.

Share this post


Link to post
Share on other sites

I have one page in one directory.

 

The subdomain is exploded from the http address and fetches the required data.

 

I think it's unnecessary extended to make multiple directories.

 

Is it the only solution?

Share this post


Link to post
Share on other sites

I don't know. I don't know of any directives in htaccess that can query the server configuration to figure out if a particular subdomain or virtual host is defined in the config files. I do know that there are ways to check if a directory exists.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...