?
Solved

mod_rewrite query: I think an easy question

Posted on 2006-11-28
11
Medium Priority
?
186 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
[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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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