Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mod_rewrite and virtual hosts

Posted on 2006-10-30
9
Medium Priority
?
1,434 Views
Last Modified: 2007-12-19
The System: Apache v2.2.2 on Solaris 9 with mod_rewrite available

This system hosts multiple virtual servers, and these are defined in ./conf/extra/httpd-vhosts.conf

All these virtual hosts are using different Domain Names from the "main" Apache server.

For one specific virtual hosts, I want to re-direct all requests for *any* page under that virtual host to a specific URL in the "main" Apache server.

Let's say the "main" Apache server considers itself "www.mydomain.tld", and the specific virtual host I want to mod_rewrite is "www.deaddomain.tld".

I want to redirect *any* page request that starts out "www.deaddomain.tld" to "www.mydomain.tld/readthis.html"

So...

www.deaddomain.tld --> www.mydomain.tld/readthis.html
www.deaddomain.tld/index.html --> www.mydomain.tld/readthis.html
www.deaddomain.tld/images/title.gif --> www.mydomain.tld/readthis.html
www.deaddomain.tld/guestbook.html --> www.mydomain.tld/readthis.html

The Question:

1) Do the mod_rewrite configuration statements go in ./conf/httpd.conf or in the Virtual Host section of ./conf/extras/httpd-vhosts.conf (I think the latter, but I want to be sure)?

2) What's the proper syntax for the Rewrite* statements?
0
Comment
Question by:PsiCop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 17840357
RewriteEngine On
RewriteRule .* http://www.mydomain.tld/readthis.html [L,R]

either in .htaccess file in DocumentRoot of the server OR in the VirtualHost section itself
0
 
LVL 16

Assisted Solution

by:HackneyCab
HackneyCab earned 400 total points
ID: 17841320
That will surely cause an infinite loop?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17841344
Well possibly. Fixed version?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mydomain.tld
RewriteCond %{HTTP_HOST} !^$ //damn http/1.0 clients!
RewriteRule .* http://www.mydomain.tld/readthis.html [L,R]
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Author Comment

by:PsiCop
ID: 17841777
Ummm....I'm confused. Shouldn't it be:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.deaddomain.tld
RewriteCond %{HTTP_HOST} !^$ //damn http/1.0 clients!
RewriteRule .* http://www.mydomain.tld/readthis.html [L,R]

I want to redirect www.deaddomain.tld/whatever to www.mydomain.tld/readthis.html - does it matter that the Domain Name is changing to one outside of the deaddomain.tld Virtual Server, or that mydomain.tld is not in a Virtual Server?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 1600 total points
ID: 17841833
The fixed version prevets from redirecting to same virtualserver, so
RewriteCond %{HTTP_HOST} !^www.mydomain.tld //if the request is not to www.mydomain.tld
RewriteCond %{HTTP_HOST} !^$ //and not damn http/1.0 client
RewriteRule .* http://www.mydomain.tld/readthis.html [L,R] //redirect to www.mydomain.tld
//as a result, the www.mydomain.tld gets never redirected
0
 
LVL 34

Author Comment

by:PsiCop
ID: 17843448
But I don't want to redirect to the same virtual server.

www.mydomain.tld is the "real" server instance, defined in httpd.conf, not a virtual server.

www.deaddomain.tld is a virtual server, defined in /extras/httpd-vhosts.conf

I want to redirect *from* deaddomain *to* mydomain

I don't understand why www.mydomain.tld is in the RewriteCond statement. Shouldn't www.deaddomain.tld be in there?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17843581
I already explained. we are redirecting to www.mydomain.tld, therefore if request is already to www.mydomain.tld - we wan tto skip it, otherwise redirect. And that what those RewriteConds do: if HTTP_HOST is not www.mydomain.tld AND  HTTP_HOST is not empty -> fire RewriteRule
0
 
LVL 34

Author Comment

by:PsiCop
ID: 17844043
Ah! Sorry, missed the !
0
 
LVL 34

Author Comment

by:PsiCop
ID: 17847188
OK, that seems to have done it. Thanks! And thanks to HackneyCab for pointing out the loop issue.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

618 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