Sign in to follow this  
Followers 0
Balderick

redirect not existing subdomain to www with htaccess

4 posts in this topic

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0