Link to home
Start Free TrialLog in
Avatar of Insoftservice inso
Insoftservice insoFlag for India

asked on

Virtual host in apache

Pointing 2 different paths to the same Apache domain name

<VirtualHost *:80>
    ##ServerAdmin webmaster@treoinfotech.com
     DocumentRoot "/var/www/xampp/htdocs/treo"
      ServerName treo.biz
      ServerAlias www.treo.biz
 </VirtualHost>

<VirtualHost *:80>
    ##ServerAdmin webmaster@treoinfotech.com
     DocumentRoot "/var/www/xampp/htdocs/blog"
      ServerName blog.treo.biz
 </VirtualHost>

I want to change blog.treo.biz to treo.biz/blog
Alias can do this method but have no idea how to do it. Have google it but failed Please help
Please give solution for both ubuntu and centos

blog is in wordpress and treo.biz is in laravel
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

Change the document root to:

         DocumentRoot "/var/www/xampp/htdocs/treo/blog"

Or you can put an htaccess using mod rewrite to change the URL -- put the .htaccess in the virtual host root for the blog:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://treo.biz/blog$1 [R=301,L]
The other option to Jan, you can add a virtual directory to the tree.biz site for /blog with the DocumentRoot from the second
Alias /blog /var/.....
Will do the same.

See Apache mod_alias
http://httpd.apache.org/docs/current/mod/mod_alias.html
Avatar of Insoftservice inso

ASKER

can u please create virtual host if possible.
I want two website running

1> www.treo.biz with the document root         "/var/www/xampp/htdocs/treo"
2> www.treo.biz/blog with the document root   /var/www/xampp/htdocs/blog
The way you outlive it, it is a single site
Not two.
Virtual host only deals with  the hostname www.treo.biz or treo.biz

The /blog is a folder within the site.

What are you after, do you want separate logs for main sire and for the /blog?

You could leave it as you have while defining a refirect rule on the treo.com site for /blog to http://blog.treo.biz
....
@arnold i hope u have not read my question. its blog.treo.biz to treo.biz/blog
You want two websites:

   www.treo.biz
   www.treo.biz/blog

The first is a fully qualified domain name and the second is a URL.  I believe that is what arnold was trying to say.

If you want to virtualize /blog, then you need to specify another fully qualified domain name.  What you have asked for is the same thing.
Lets try it this way.
A residence has two entrances. Front door and basement door.
Entry through front door gets one into the Living room. Entry at the basement door first location is the basement.
Treo.biz or www.treo.biz is the front door.
Entry to the basement door equivalent to (blog.treo.biz)

You can either give instructions enter front door or enter basement door which is what you have defined.

What you are asking for is a variation of enter front door (treo.biz) or enter front door and go down the stairs to the basement (treo.org/blog) in this case the person only needs to know about the front door, thus only one virtualHost entry for www.treo.biz/treo.biz.

Hope this illustration makes it clearer.
The suggestion to maintain two virtual host as you hve them, is to have a sign on the front door, "if you need to get access to the basement, use basement door."
That's awfully confusing.  Let's stick with fully qualified domain name and URLs.
Jan,

I think the example was a way to convey the difference.

two way to reach the same location.


graphical illustration required too much ascii text to ....

An alias/redirect from /blog to blog.treo.biz is the most straightforward approach.

reloacting the htdocs/blog to htdocs/treo/blog is an approach, but will require validation that the wordpress setup does not fail because of configured paths rely on it being in htdocs/blog and not in htdocs/treo/blog.

The asker has yet to respond why two virtual host entries are needed.
Though, separating the wordpress part from their regular site paths to make sure an error does not wipe the wordpress site........
SOLUTION
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jan,

The two virualhost entries use different DocumentRoot.
www.treo.biz htdocs/treo for the main site
blog.treo.biz htdocs/blog for the blog (wordpress) site.
The asker wants to consolidate URL reflection while maintain two virtualhosts

since blog is driven by wordpress, it is or could pose an issue if it were to be setup under the single
treo.biz virtualhost
Often the reason for separating is separate memory space/handlers for the wordpress as compared to the main site, treo.biz.

Without an understanding on why the asker is seeking this change, we can go back and forth trying to guess all the possible variances that might make sense from the log data handling, to other ......
Right but www.treo.biz and www.treo.biz/blog is one virtual host if you refer to the author's request.  

If you also read the original question, the regular website is not wordpress.
The user wants as you noted www.treo.biz and www.treo.biz/blog as separate virtualhosts presumably because of the wordpress portion and the only way to achieve it is:
1) under the treo.biz setup a redirect for /blog to blog.treo.biz
2) alias /blog to /var/www/xamp/htdocs/blog which is more risky as the wordpress functionality might break
3) create a symbolik link as Jan pointed out in /var/www/xamp/htdocs/treo/blog which points back to /var/www/xamp/htdocs/blog (FollowSymLinks option has to be added to the main treo.biz site) wordpress functionality might be compromised.... because of path change in requests....
I never said to create a symbolic link.  It's a logical reference to rewrite the URL to something different.
Jan,


Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://treo.biz/blog$1 [R=301,L]

Where are you placing the redirect?

You either redirect, or you followsymlinks doing both seems counter intuitive.
akin to a double-negative making two changes to achieve what one change can do.
Yet it works.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why then set/use FollowSymLink?

Imho, would set the redirect on treo.biz/blog to blog.treo.biz and be done with that...
If you don't specify that then rewrite engine won't work.   It's for per directory rewrites.
<VirtualHost *:80>
   DocumentRoot "/var/www/test_blog"
   ServerName blog.treo.biz
   Redirect 301 / http://treo.biz/blog/
</VirtualHost>

will it be implemented to all links of wordpress

As below code is not working as expected

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.treo.biz$ [OR]
RewriteRule (.*)$ http://treo.biz/blog/$1 [R=301,L]
</IfModule>
It works for few links but fail for other links. just confused why its happening if you have any idea please share
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes @arnold i moved it htdocs/treo/blog  .
But its not redirecting even i kept redirection rule in apache but even it failed .
blog.ridlr.in had to be redirected to ridlr.in/blog it works for few links but fail for other
http://blog.ridlr.in/category/delhi/
Your pattern match includes a test on the ending, ($)

Your conditional test includes an end terminator

The issue is that you intent on maintaing the old references..

Enabling tracing/reord could shed light on the issue is the redirect attempt failed.
Redirect 301 / http://ridlr.in/blog/  even its not working
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I doubt i have placed rewrite engine on in virtual host.

<VirtualHost *>
  ServerName www.example.com
  Redirect 301 / http://example.com/
</VirtualHost>

Yes i have restarted apache
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how to do logging of redirect i virtual host
Please provide some more light on tracing or if possible please provide the code if possible
The first part of the document referenced in the prior deals with setting the trace. Once enabled, tge data can be extracted from the log. error_log

From the link, add to your virtualhost definition
LogLevel alert rewrite:trace3
It was too near but i have resolved the issue earlier.
Logs did not helped me so much but ya learned something new