Reputation: 27
I don't really know how to describe my problem in a sentence so instead I will explain with an example:
Lets say I have a folder structure that looks like this:
/root
/root/clientfolder1/testfile.php
/root/clientfolder2/testfile.php
etc...
and the testfile.php is the same across all subfolders.
Now say I just pushed out a new file called testfile2.php accross all subfolders so now testfile2.php exists within all subfolders.
I add a redirect to point the old testfile.php to the new testfile2.php
So, in my .htaccess I add the following (Yes, 'RewriteEngine On' is set already in the .htaccess file):
RewriteRule (.*)/testfile\.php /$1/testfile2.php [R=301,L]
okay now everything appears to work fine at this point however ( and this is where things get tricky) in my htaccess file I also have rules setup for multiple domains to point to specific folders like this:
RewriteCond %{HTTP_HOST} domain-one.com
RewriteCond %{REQUEST_URI} !^/clientfolder1
RewriteRule ^(.*)$ clientfolder1/$1 [L]
RewriteCond %{HTTP_HOST} domain-two.com
RewriteCond %{REQUEST_URI} !^clientfolder2
RewriteRule ^(.*)$ clientfolder2/$1 [L]
etc...
I also have a main (default domain name) that is used for my main site (files in root) lets call it main-domain.com
So the following works:
domain-one.com/testfile.php
domain-one.com/testfile2.php
domain-two.com/testfile.php
domain-two.com/testfile2.php
main-domain.com/clientfolder1/testfile.php
main-domain.com/clientfolder2/testfile.php
Now here's my question/problem:
My new redirect that I added above to replace the testfile.php with testfile2.php causes the following to happen:
domain-one.com/testfile.php redirects to: main-domain.com/clientfolder1/testfile2.php
but I need it to redirect to domain-one.com/testfile2.php
I cannot get this to work... and getting frustrated as I am sure there is a simple solution to this and I am just missing something obvious. Can this be done and how?
Thanks in advance you your help - very much appreciated!!
Upvotes: 0
Views: 397
Reputation: 200373
Apache does exactly what your rules tell it to do.
RewriteCond %{HTTP_HOST} domain-one.com
If the domain is "domain-one.com" ...
RewriteCond %{REQUEST_URI} !^/clientfolder1
... and the URI does not begin with "/clientfolder1" ...
RewriteRule ^(.*)$ clientfolder1/$1 [L]
... then prepend the URI with "clientfolder1/".
Upvotes: 1