Link to home
Start Free TrialLog in
Avatar of bcops
bcops

asked on

mod_rewrite query: I think an easy question

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
Avatar of Robin Hickmott
Robin Hickmott

Try

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^*.\.domainB\.com$
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]
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]
Avatar of bcops

ASKER

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



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.

Avatar of bcops

ASKER



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.


Avatar of bcops

ASKER

Hi,

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

Ben

And

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

does work?
Avatar of bcops

ASKER

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.







Avatar of bcops

ASKER

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.




ASKER CERTIFIED SOLUTION
Avatar of Robin Hickmott
Robin Hickmott

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bcops

ASKER

Ja, eventually got that to work. Seemed better. Will award points.