Solved

Apache rewrite rule help needed!

Posted on 2006-11-21
4
282 Views
Last Modified: 2010-03-04
0
Comment
Question by:894359
[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
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 17989591
Try

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.commandandconquer\.com/exclusive$ [NC]
RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/exclusive/$1 [R=301,L]
0
 

Author Comment

by:894359
ID: 17991382
Doesn't work?  What is the precedence for vhosts and rewrites? What I need to do is have:

www.commandandconquer.com               
www.commandandconquer.ea.com         
commandandconquer.ea.com                
commandandconquer.com            

all point to :

http://www.ea.com/commandandconquer/


but the one special condition I have is that  www.commandandconquer.ea.com/exclusive goes to http://www.ea.com/commandandconquer/exclusive/

Not sure how to do this?

Currently vhosts contains:

www.commandandconquer.com               http://www.ea.com/commandandconquer/
www.commandandconquer.ea.com            http://www.ea.com/commandandconquer/
commandandconquer.ea.com                http://www.ea.com/commandandconquer/
commandandconquer.com                   http://www.ea.com/commandandconquer/

which I removed and tried adding this to the prod.conf file:

RewriteCond ${lowercase:%{SERVER_NAME}} ^(www.commandandconquer.ea.com)$ [OR]
RewriteCond ${lowercase:%{SERVER_NAME}} ^(commandandconquer.ea.com)$
RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.commandandconquer\.com/exclusive$ [NC]
RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/exclusive/$1 [R=301,L]

But the exclusive piece never worked, everything went to http://www.ea.com/commandandconquer/
0
 
LVL 13

Accepted Solution

by:
rhickmott earned 500 total points
ID: 17994622
It will run the first rule and if not executed it will move onto the first ( The L Flag ) I must apologise in there was a slight wrror in the first staatement it should have been

RewriteCond %{HTTP_HOST} !^www\.commandandconquer\.ea\.com/exclusive$ [NC]
(Note the .ea bit)


It Depends on where you are coming from assumingly all these domains are hosted on the one server an IP and your using VirtualHosts.

The ones that are straight redirects are easy you can do this in your VirtualHost contrainers.

<VirtualHost xxx.xxx.xxx.xxx:80> (or whatever your using)
       ServerName *.commandandconquer.com
       Redirect Permanent / http://www.ea.com/commandandconquer/
</VirtualHost>

<VirtualHost xxx.xxx.xxx.xxx:80> (or whatever your using)
       ServerName *.ea.com
       RewriteEngine on
       RewriteCond %{HTTP_HOST} !^.*\.commandandconquer\.ea\.com/exclusive$ [NC]
       RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/$1 [R=301,L]
       RewriteRule ^(.*)$ http://www.ea.com/commandandconquer/exclusive/$1 [R=301,L]
</VirtualHost>


Basically this says if the user is NOT going to <anything>.commandandconquer.ea.com/exclusive kick them to http://www.ea.com/commandandconquer/ and stop processing more rules.

So if this rule is not run therefore it MUST be a request for the exclusive site so then it will direct them to http://www.ea.com/commandandconquer/exclusive/
0
 

Author Comment

by:894359
ID: 18000320
RewriteCond ${lowercase:%{SERVER_NAME}} ^(www\.commandandconquer\.ea\.com)$ [OR]
RewriteCond ${lowercase:%{SERVER_NAME}} ^(commandandconquer\.ea\.com)$
RewriteRule ^/exclusive$ http://www.ea.com/commandandconquer/exclusive/ [L,R]
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…

726 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