Forum Moderators: phranque
http://www.example.com/affiliate/
There are hundreds of links using that subdirectory (like example.com/affiliate/user.php?123) and I need everything to forward now to:
[affiliate.example.com...] (or whatever the link may be)
I do not need every subdirectory to do this. I need only the /affiliate/ directory.
I tried this but all browsers are timing out saying it's endlessly redirecting.
RewriteRule ^affiliate(.*)$ http://affiliate.example.com$1 [R=301] Any ideas?
If this is the case, you'll need to use a RewriteCond testing THE_REQUEST so that external redirection only takes place if the client directly requests the subdirectory, and not if the subdirectory is requested as the result of an internal rewrite of the subdomain URL.
Jim
RewriteCond %{HTTP_HOST}!^www.example.com$
RewriteRule ^/?(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^/?affiliate/(.*)$ http://affiliate.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^affiliate\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^affiliate/(.*)$ http://affiliate.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^(www¦affiliate)\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^affiliate/(.*)$ http://affiliate.example.com/$1 [R=301,L]
Do not end-anchor hostname patterns, unless you account for a (valid) port name appended to the hostname in the request header. Otherwise, any client that does append a port number will 'break' your RewriteRules. If you feel you must end-anchor the hostname patterns, then use something like any one of these:
RewriteCond %{HTTP_HOST} !^www\.example\.com(:80)?$
RewriteCond %{HTTP_HOST} !^www\.example\.com(:80¦443)?$
RewriteCond %{HTTP_HOST} !^www\.example\.com(:[0-9]+)?$
I type in something like:
http://www.example.com/affiliate/account.php
it then tries to forward to:
then it just forwards right back to:
http://www.example.com/affiliate/account.php
And then the browser times out saying there are too many redirects.
For what it's worth, I'm running Apache 1.3.37.
[edited by: JPigford at 6:53 pm (utc) on Nov. 10, 2007]
If you used a 'control panel' then it's likely that it created a rewriterule in the server config file that is conflicting with your existing rule as described above. Also, some control panels will show you the config file they create -- Is this information accessible to you?
Jim
<VirtualHost XX.XX.XX.XX>
ServerAlias www.affiliate.example.com
ServerAdmin webmaster@affiliate.example.com
DocumentRoot /home/user/public_html/affiliate
BytesLog domlogs/affiliate.example.com-bytes_log
User user
Group user
ServerName affiliate.example.comUser user
Group user
CustomLog /usr/local/apache/domlogs/affiliate.example.com combined
ScriptAlias /cgi-bin/ /home/user/public_html/affiliate/cgi-bin/
</VirtualHost>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /affiliate/
RewriteRule ^affiliate/(.*)$ http://affiliate.example.com/$1 [R=301,L]
Jim
[edited by: jdMorgan at 9:55 pm (utc) on Nov. 10, 2007]