Avatar of Insoftservice inso
Insoftservice inso
Flag 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
Apache Web ServerLinux

Avatar of undefined
Last Comment
Insoftservice inso

8/22/2022 - Mon
Jan Bacher

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]
arnold

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
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
arnold

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
....
Insoftservice inso

ASKER
@arnold i hope u have not read my question. its blog.treo.biz to treo.biz/blog
Jan Bacher

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnold

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."
Jan Bacher

That's awfully confusing.  Let's stick with fully qualified domain name and URLs.
arnold

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........
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Jan Bacher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
arnold

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 ......
Jan Bacher

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.
arnold

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....
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jan Bacher

I never said to create a symbolic link.  It's a logical reference to rewrite the URL to something different.
arnold

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.
Jan Bacher

Yet it works.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jan Bacher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnold

Why then set/use FollowSymLink?

Imho, would set the redirect on treo.biz/blog to blog.treo.biz and be done with that...
Jan Bacher

If you don't specify that then rewrite engine won't work.   It's for per directory rewrites.
Insoftservice inso

ASKER
<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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Insoftservice inso

ASKER
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/
arnold

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.
Insoftservice inso

ASKER
Redirect 301 / http://ridlr.in/blog/  even its not working
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Insoftservice inso

ASKER
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
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Insoftservice inso

ASKER
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
arnold

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Insoftservice inso

ASKER
It was too near but i have resolved the issue earlier.
Logs did not helped me so much but ya learned something new