Solved

mod_rewrite query: I think an easy question

Posted on 2006-11-28
11
179 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with htaccess under apache 7 23
PHP temp path missing 4 48
XAMPP 14 40
How to find /read Apache log error file ? 5 96
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…
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). #…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now