[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

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
0
Insoftservice
Asked:
Insoftservice
  • 14
  • 9
  • 8
6 Solutions
 
Jan SpringerCommented:
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]
0
 
arnoldCommented:
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
0
 
InsoftserviceAuthor Commented:
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
arnoldCommented:
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
....
0
 
InsoftserviceAuthor Commented:
@arnold i hope u have not read my question. its blog.treo.biz to treo.biz/blog
0
 
Jan SpringerCommented:
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.
0
 
arnoldCommented:
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."
0
 
Jan SpringerCommented:
That's awfully confusing.  Let's stick with fully qualified domain name and URLs.
0
 
arnoldCommented:
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........
0
 
Jan SpringerCommented:
Technically, there is only one.  Both examples provided by the author point to a single [virtual] host container.
0
 
arnoldCommented:
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 ......
0
 
Jan SpringerCommented:
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.
0
 
arnoldCommented:
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....
0
 
Jan SpringerCommented:
I never said to create a symbolic link.  It's a logical reference to rewrite the URL to something different.
0
 
arnoldCommented:
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.
0
 
Jan SpringerCommented:
Yet it works.
0
 
arnoldCommented:
What is the additional change?


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

are you creating a symbolic link in /var/www/xamp/htdocs/treo/blog that points to /var/www/xamp/htdocs/blog as well as configuring the redirect on http://blog.treo.biz?
While at the same time adding the FollowSymLink to the treo.biz virtualhost which is where it is need.


To What end?
So the user maintains two virtualhosts but only records single encounters on blog.treo.biz.
Fortunately I have two functional hands, so I can scratch my right ear with my left hand, is it the most efficient way of relieving the itchiness?:-)
0
 
Jan SpringerCommented:
No.  His wordpress installation will have to change to live under treo.biz document root.

The URL rewrite is to handle stale DNS  that lands on blog.treo.biz until he can get rid of that virtual host.  Or, he can leave that virtual host there and still rewrite the URL to the new document location.
0
 
arnoldCommented:
Why then set/use FollowSymLink?

Imho, would set the redirect on treo.biz/blog to blog.treo.biz and be done with that...
0
 
Jan SpringerCommented:
If you don't specify that then rewrite engine won't work.   It's for per directory rewrites.
0
 
InsoftserviceAuthor Commented:
<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
0
 
arnoldCommented:
Did you alter the directory for Wordpress from htdocs/blog to htdocs/treo/blog or create a symbolic link and made sure it works or create an alias within the treo.biz for /blog to point to /var/www/xamp/htdocs/blog
Or use symbolic link.
And then make sure it works as expected before forwarding blog.treo.biz to the new path, reference.

Enable match/refirect tracing this way you can see.

When it does not work, it likely fails to meet your wordpress config requirements, either kicking the user to the main page or ...
0
 
InsoftserviceAuthor Commented:
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/
0
 
arnoldCommented:
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.
0
 
InsoftserviceAuthor Commented:
Redirect 301 / http://ridlr.in/blog/  even its not working
0
 
arnoldCommented:
Where are you placing  this, see Jan, do you have rewriteengine on to make sure it is turned on?

Look at Apache mod_rewrite and add tracing/logging of rewrites.
Apache reloaded/restarted after the changes?
0
 
InsoftserviceAuthor Commented:
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
0
 
arnoldCommented:
If you have another entry where www.example.com is ServerAlias. this virtualHOST might not match any request.

Enable tracing
http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Instead of guessing/presuming that the Redirect is being evaluated, you will know for certain.

Enable logging right before the rewrite and end the loging right after it is done.

DEpending on your version, ........ newer versions can be limited where the tracing can be enabled, in older version it is enabled in a more general way having more data that you might be interested in.
0
 
InsoftserviceAuthor Commented:
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
0
 
arnoldCommented:
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
0
 
InsoftserviceAuthor Commented:
It was too near but i have resolved the issue earlier.
Logs did not helped me so much but ya learned something new
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 14
  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now