SteveS
04-19-2011, 06:28 PM
I need some advise on redirecting from one (domain/directory) to another (domain) when the (domain/directory) and the (domain) point to the same directory on the server. I thought I would check here before opening a ticket.
The goal - Anytime anyone navigates to http://www.mydomain.com/forum/ I want them to be directed to http://forum.mydomain.com. I want to separately track traffic to the forum and the main pages of the site. I attempted to use the redirect wizard in cPanel but I received the following error.
Redirecting forum to http://forum.mydomain.com will cause a redirection loop because 'http://mydomain.com/forum'
which is located at /home3/mydirectory/public_html/mydomain/forum
is above 'http://forum.mydomain.com'
which is located at /home3/mydirectory/public_html/mydomain/forum
Domain mydomain.com points to /home3/mydirectory/public_html/mydomain
Domain forum.mydomain.com points to /home3/mydirectory/public_html/mydomain/forum
I am not in any way an apache expert, but it would seem that the following should work.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^forum\/(.*)$ "http\:\/\/forum\.mydomain\.com" [R=301,L]
I was under the impression that apache looks at domains and then directories to take action and does not first translate everything to a full directory path to make a decision. I am aware that mod_rewrite can be used to direct someone to "www.adomain.com" when they attempt to navigate to just "adomain.com" and obviously both "www.adomain.com" and "adomain.com" point to the same directory.
Before I get crazy and attempt to manually modify the .htaccess file, I wanted some feedback.
Thanks,
Steve
The goal - Anytime anyone navigates to http://www.mydomain.com/forum/ I want them to be directed to http://forum.mydomain.com. I want to separately track traffic to the forum and the main pages of the site. I attempted to use the redirect wizard in cPanel but I received the following error.
Redirecting forum to http://forum.mydomain.com will cause a redirection loop because 'http://mydomain.com/forum'
which is located at /home3/mydirectory/public_html/mydomain/forum
is above 'http://forum.mydomain.com'
which is located at /home3/mydirectory/public_html/mydomain/forum
Domain mydomain.com points to /home3/mydirectory/public_html/mydomain
Domain forum.mydomain.com points to /home3/mydirectory/public_html/mydomain/forum
I am not in any way an apache expert, but it would seem that the following should work.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^forum\/(.*)$ "http\:\/\/forum\.mydomain\.com" [R=301,L]
I was under the impression that apache looks at domains and then directories to take action and does not first translate everything to a full directory path to make a decision. I am aware that mod_rewrite can be used to direct someone to "www.adomain.com" when they attempt to navigate to just "adomain.com" and obviously both "www.adomain.com" and "adomain.com" point to the same directory.
Before I get crazy and attempt to manually modify the .htaccess file, I wanted some feedback.
Thanks,
Steve