Forum Moderators: phranque

Message Too Old, No Replies

htaccess 301 Redirect only for root

Subfolder files with same name being affected

         

vimello

12:46 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



Hi there!

I have made changes to some pages of my website, and they no longer exist, but they are ranked well in search engines. I am doing this in my htaccess file:

redirect 301 /oldfile.html http://www.example.com/newfile.html

These files are located on my root folder (public_html). The problem is that I have another domain in that hosting account (public_html/domain) and it has an oldfile.html file into it. So, it keeps redirecting to the site hosted in the root's newfile.html, whereas I wouldn't like it to redirect at all.

Could anyone help me? Thank you so much!

[edited by: jdMorgan at 12:51 pm (utc) on Oct. 27, 2008]
[edit reason] Please use example.com [/edit]

jdMorgan

12:53 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to use mod_rewrite, and use a RewriteCond to test %{HTTP_HOST} so that the following RewriteRule is only applied to the domain that you want it to apply to, or so that it is NOT applied to the domain that you don't want it applied to.

Take care to correctly handle both www- and non-www variants of the hostname -- or better yet, add another rule to redirect the non-canonical hostnames to the canonical hostnames (e.g. redirect non-www to www (or vice versa) for both of your domains).

See Apache mod_rewrite RewriteCond, RewriteRule, and RewriteEngine directives. Links to this documentation and other useful resources are cited in our Forum Charter (see link at top left of this page).

Jim

vimello

12:56 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



Hi Jim, thanks for the quick response. I will look into that!

One question, will the search engines handle these requests as they would handle a 301 permanent redirect (as in, not modifying pagerank nor penalizing the website?)

Thanks!

jdMorgan

1:26 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure I understand that question, since these *are* 301 redirects, if implemented properly.

Use the Live HTTP Headers add-on for Firefox and Mozilla-based browsers to confirm.

Jim