Solved

Virtual host in apache

Posted on 2016-08-26
31
72 Views
Last Modified: 2016-09-12
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
Comment
Question by:Insoftservice
  • 14
  • 9
  • 8
31 Comments
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
@arnold i hope u have not read my question. its blog.treo.biz to treo.biz/blog
0
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
That's awfully confusing.  Let's stick with fully qualified domain name and URLs.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 28

Assisted Solution

by:Jan Springer
Jan Springer earned 250 total points
Comment Utility
Technically, there is only one.  Both examples provided by the author point to a single [virtual] host container.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
I never said to create a symbolic link.  It's a logical reference to rewrite the URL to something different.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
Yet it works.
0
 
LVL 76

Assisted Solution

by:arnold
arnold earned 250 total points
Comment Utility
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
 
LVL 28

Assisted Solution

by:Jan Springer
Jan Springer earned 250 total points
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Why then set/use FollowSymLink?

Imho, would set the redirect on treo.biz/blog to blog.treo.biz and be done with that...
0
 
LVL 28

Expert Comment

by:Jan Springer
Comment Utility
If you don't specify that then rewrite engine won't work.   It's for per directory rewrites.
0
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
<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
 
LVL 76

Assisted Solution

by:arnold
arnold earned 250 total points
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
Redirect 301 / http://ridlr.in/blog/  even its not working
0
 
LVL 76

Accepted Solution

by:
arnold earned 250 total points
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
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
 
LVL 76

Assisted Solution

by:arnold
arnold earned 250 total points
Comment Utility
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
 
LVL 15

Author Comment

by:Insoftservice
Comment Utility
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
 
LVL 76

Expert Comment

by:arnold
Comment Utility
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
 
LVL 15

Author Closing Comment

by:Insoftservice
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now