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
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
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]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.domainA\.com$
RewriteRule ^/folderA/(.*)$ http://www.domainB.com/$1 [R=301,L]
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
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.
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.
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.
ASKER
Hi,
So, can anyone help with this?
I'm not getting anywhere with this.
Ben
So, can anyone help with this?
I'm not getting anywhere with this.
Ben
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/idea s most welcome:
Thanks, Ben.
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/idea
Thanks, Ben.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ja, eventually got that to work. Seemed better. Will award points.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^*.\.domainB\.com$
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]