Solved

mod_rewrite query: I think an easy question

Posted on 2006-11-28
11
184 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

732 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