Forum Moderators: phranque

Message Too Old, No Replies

unique redirect problem

301 redirect

         

modine

9:44 pm on Jun 5, 2007 (gmt 0)

10+ Year Member



Hi,

I have a very unique problem. I have reorganized my directories and have been able to get the main site working the way I want it. But now 2 of my other directories are also redirect to my one site. The other directories are separate sites which no longer come in. I'm not sure if it's because I redirected the http://example.com to redirect to http://www.example.com or if it's something altogether different. I have tried many things and nothing works. Just to give you an idea, eggs-sample.com now redirects to example.com.com. How can I make my directories come in correctly using .htaccess file?

Thanks,
modine

[edited by: jdMorgan at 9:49 pm (utc) on June 5, 2007]
[edit reason] Example.com [/edit]

jdMorgan

9:54 pm on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's likely that your domain canonicalization code is at fault, especially if you just copied it without modifications to allow for your alternate hosted domain names.

Please post the code you're using after changing all domain names/hostnames to example.com, example.net, etc. If you need more 'safe' domains, then please use WebmasterWorld.com, cnn.com, and other well-know domains, and not your own. This is for your protection as well as that of all of our members.

Thanks,
Jim

modine

9:58 pm on Jun 5, 2007 (gmt 0)

10+ Year Member



Sorry, below is the entire code in my .htaccess file

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.example.com
AuthUserFile /www3/example/_vti_pvt/service.pwd
AuthGroupFile /www3/example/_vti_pvt/service.grp

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}!^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Redirect 301 /store2/ http://www.example.com/

jdMorgan

10:28 pm on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that code clearly redirects anything that is NOT www.example.com to www.example.com.

Replace the last three lines with this:


RewriteRule ^store2/(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+\.)*example\.com
RewriteRule (.*) http://www.example.com/$1 [L,R=301]

By changing the Redirect to a RewriteRule, we guarantee that the /store2/ redirect executes first, avoiding a 'chained' or double redirect for /store2/ URLs.

By changing the logic of the non-www example.com detection, we avoid any redirection of your other hosted domains.

Otherwise, the function is identical.

You may wish to duplicate the canonicalization code for your other domains as well. Or, if all of your domains are canonicalized to the "www" version, you could do something like this:


RewriteRule ^store2/(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+\.)*(example\.com¦2nd-domain\.com¦3rd-domain\.net)
RewriteRule (.*) http://www.%2/$1 [L,R=301]

Replace the broken pipe "¦" characters in the code above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

modine

10:43 pm on Jun 5, 2007 (gmt 0)

10+ Year Member



Thank you so much. I try this and let you know how it does.

Thanks again

modine

11:15 pm on Jun 5, 2007 (gmt 0)

10+ Year Member



Hi,

I changed the code but the 2 domains are still being redirected to the main site. Any other suggestions.

Thanks,
modine

modine

12:13 am on Jun 6, 2007 (gmt 0)

10+ Year Member



I'm not sure I'm putting the code in correctly because it still doesn't work the way it should with the other 2 domains. I am trying everything I can. Still need help!