Forum Moderators: phranque

Message Too Old, No Replies

301 redirect addon domain

         

MWpro

3:14 am on Feb 17, 2009 (gmt 0)

10+ Year Member



How can I direct the following

[maindomain.com...] (yes, the folder's name is "addondomain.com"

to

[addondomain.com...]

?

I have tried

RewriteEngine on
RewriteCond %{HTTP_HOST} ^maindomain.com/~username/addondomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.maindomain.com/~username/addondomain.com$
rewriteRule ^(.*) [addondomain.com...] [R=301,L]

But this is not working.

[edited by: MWpro at 3:15 am (utc) on Feb. 17, 2009]

jdMorgan

3:57 pm on Feb 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The %{HTTP_HOST} variable contains only the requseted hostname, and perhaps an appended port number. It will never contain any part of the requested URL-path. Therefore, neither of your RewriteConds will ever match a valid HTTP Host request header. So,

RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com
RewriteRule ^~username/addondomain\.com(.*)$ http://www.addondomain.com$1 [R=301,L]

is closer to what you want, if not exactly-right. Also, mod_userdir may affect this request before mod_rewrite can be invoked, so I'm not sure it will work.

Jim

MWpro

5:19 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



This seems to have not worked; please advise.

jdMorgan

11:13 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't see your server. I can't see your error logs. I don't know how you tested, what results you got, or how those results differed from what you expected... Please advise.

Jim

MWpro

6:27 am on Feb 20, 2009 (gmt 0)

10+ Year Member



I went to the long URL after adding it to my .htaccess file. It did not redirect me. How else would you test this?

jdMorgan

7:39 pm on Feb 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at the server error log, and look at the server response headers using the "Live HTTP Headers" add-on for Firefox/Mozilla browsers.

There are many, many factors involved in getting the code "just right" and unfortunately, you'll have to do most of the work to figure it out; There are no "one-size-fits-all" or universal cut-and-paste solutions, because server configurations, URL-structure, and file organization differs so much between sites and servers.

Therefore, a lot of experimentation and troubleshooting is required, especially in cases when a new rule is the only rule in .htaccess, or when there are very few rules. If this rule *is* the only rule, then try simpler tests, such as:


RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

Then request http://www.example.com/foo.html from your server. If you end up at Google, then it worked, and the problem is likely just an incorrect RewriteRule pattern. If not, then it's likely a server configuration or mod_rewrite set-up problem.

Jim