LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-04-2012, 09:40 AM   #1
linux_kung_fu
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: 0
rewrite rule for apache


What if I need to 301 redirect (www.)example.com to a specific URL? I know below should work, but I can't seem to get it to work in one stanza instead of two, what am I missing here?

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/section$ http://foobar.example.com/blargh [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^/section$ http://foobar.example.com/blargh [R=301,L]


thanks!
 
Old 07-04-2012, 10:28 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi there,

Are you saying the above is not working, or that it does work, but you want to rewrite it in one stanza?

To just combine the 2 rules, the following should work:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^/section$ http://foobar.example.com/blargh [R=301,L]
</IfModule>
In what context is this used - VirtualHost, Directory; in a .conf file, or in a .htaccess file?

Where does /section fit into your requirement?
 
1 members found this post helpful.
Old 07-04-2012, 10:35 AM   #3
linux_kung_fu
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: 0
Hello,

This should be good. Just wanted one stanza instead of two. Anything that goes to http://example.com/section or http://www.example.com/section 301 redirects to http://foobar.example.com/blargh

This is inside a vhost config for apache primarily. Thanks again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache rewrite rule sunlinux Linux - Newbie 5 11-14-2011 07:06 AM
apache rewrite rule sunlinux Linux - Newbie 10 11-11-2011 05:01 AM
apache rewrite rule sunlinux Linux - Server 2 09-25-2011 02:03 PM
Need help with apache Rewrite Rule? your_shadow03 Linux - Newbie 1 01-21-2010 07:12 AM
Apache rewrite rule help kinetik Linux - Software 1 11-05-2007 11:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration