[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mod_rewrite query: I think an easy question

Posted on 2006-11-28
11
Medium Priority
?
189 Views
Last Modified: 2010-03-04
Hi,
Wonder if anyone can help. I've got:

www.domainA.com/folderA/[lots of pages]

I want to setup a mod_rewrite cond/rule so that whenever anyone goes to www.domainA.com/folderA/any/page/URL/ they end up going to www.domainB.com/any/page/URL
I have tried following in a .htaccess file (.htaccess as shared space):


------------------
      Options +FollowSymLinks
      RewriteEngine On

      # This says that whatever we were reached by, e.g. /xyz, we were actually reached by "/". Not quite sure what the pt was in this context.
      RewriteBase /

      RewriteCond %{REQUEST_URI} ^/folderA/$
      RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]
------------------

but no luck. Any suggestions?
Thanks, Ben
0
Comment
Question by:bcops
  • 6
  • 4
11 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 18033391
Try

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^*.\.domainB\.com$
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18033413
Sorry missed out the folder part

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^.*\.domainA\.com$
RewriteRule ^/folderA/(.*)$ http://www.domainB.com/$1 [R=301,L]
0
 

Author Comment

by:bcops
ID: 18035370
Hi,

Thanks for the reply. Slight ammendment required on my part - it's actually redirection from www.domainA.co.uk/folderA/any/page/URL/ they end up going to www.domainB.com/any/page/URL
I've tried following in .htaccess:

      RewriteCond %{HTTP_HOST} ^.*\.domainA\.co\.uk$
      RewriteRule ^/folderA/(.*)$ http://www.domainB.com/$1 [R=301,L]

No joy though. Doesn't work.

I've also tried validating the mataching condition in PHP and this works OK, so don't understand why it doesn't redirect ......
Ben



0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 13

Expert Comment

by:rhickmott
ID: 18035393
Try dumping the / off the front

so

================================================
     RewriteCond %{HTTP_HOST} ^.*\.domainA\.co\.uk$
     RewriteRule ^folderA/(.*)$ http://www.domainB.com/$1 [R=301,L]
================================================

     RewriteCond %{HTTP_HOST} ^.*\.domainA\.co\.uk$
     RewriteRule ^/folderA/(.*)$ http://www.domainB.com/$1 [R=301,L]

will not work as your attempting to look for /subfolder/FolderA/ but without a .* or a condition before the / the rule can never be true.

0
 

Author Comment

by:bcops
ID: 18035456


Thanks .... but  ... ..... so now tried:

      RewriteCond %{HTTP_HOST} ^.*\.domainA\.co\.uk$
      RewriteRule ^redir/(.*)$ http://www.domainB.com/$1 [R=301,L]

Where redir is the folder that was named folder A.
Still no dice, not working.


0
 

Author Comment

by:bcops
ID: 18038594
Hi,

So, can anyone help with this?
I'm not getting anywhere with this.

Ben

0
 
LVL 27

Expert Comment

by:caterham_www
ID: 18041755
And

RewriteEngine On
RewriteRule ^  http://www.google.com [R,L]

does work?
0
 

Author Comment

by:bcops
ID: 18044182
Hi,
Thanks for the response:

1.  Following works:
RewriteEngine On
RewriteRule ^  http://www.google.com [R,L]

2. Following works:
RewriteEngine On
RewriteRule ^alice.html$ bob.html

3. Following does not work:
RewriteEngine On
RewriteRule ^/redir/alice.html$ bob.html      

Any thoughts/contribtions/ideas most welcome:
Thanks, Ben.







0
 

Author Comment

by:bcops
ID: 18052955
OK, I think I have a solution:
      RewriteRule ^folderA(.*) http://www.domainB.com/$1 [R=301,L]
without any RewiteCond (so at the top of the .htaccess file), and with the .htaccess file residing in the root folder of the space.

This appears to work.




0
 
LVL 13

Accepted Solution

by:
rhickmott earned 1500 total points
ID: 18052976
the only problem with that is that

folderAbcde and folderAbc.file will also direct.

what about

RewriteRule ^folderA/(.*) http://www.domainB.com/$1 [R=301,NC,L]


The NC will make your search Non Case Sensitive and the / will make sure that folderA is a folder and not a file or part name of.
0
 

Author Comment

by:bcops
ID: 18053068
Ja, eventually got that to work. Seemed better. Will award points.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month18 days, left to enroll

831 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