?
Solved

mod_rewrite and virtual hosts

Posted on 2006-10-30
9
Medium Priority
?
1,430 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 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