Forum Moderators: phranque
So, here goes... I still have one problem to solve, if anyone knows how to do it... My searches on Y! for my site return the IP address, instead of the domain name (well, actually it seems to return both at times). I think it may be costing me a duplicate content penalty of some sort. Anyway, I would like to have the use of the IP address to be redirected to the top domain name with a 301, but can't figure out what the string should be in the .htaccess file. I've experimented a bit, and found strings like:
redirect 301 [mydomain.com...]
redirect 301 / [mydomain.com...]
..to redirect the ip address to the top domain (http://www.mydomain.com), but when I run a header check, www.mydomain.com is _also_ redirected as a 301...not good. I can't figure out what to put in the .htaccess string to include do something like this:
redirect 301 #$!@.IP.ad.rs [mydomain.com...]
...and actually make it work. I think I'm overlooking something, as the above string seems to do nothing.
As usual, any help is much appreciated!
Dave
I've uploaded the following as an experiment (thanks, Jim, hope you have a great vacation!), and found that it would redirect someone entering the ip only, to the domain name...
Options +FollowSymLinks
RewriteEngine on
# redirect all valid domain aliases to the www form
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]
However, it caused another problem... I only want the search engine or people who enter!@#.my.IP.ad to go to www.scootworks.com. I don't want everything that starts with!@#.my.IP.ad to be redirected, as that is screwing up my shopping cart. Example, if!@#.my.IP.ad redirects to www.mysite.com, that's great. But!@#.my.IP.ad/anything_else needs to be left alone...if that makes any sense... Any ideas on what I can do to the above statement to fix that?
Thanks a million!
Dave
I am not sure exactly what your file is called for the index, but if you substitute rule's regular expression, which is a 'catch all', with a more specific pattern, you should be fine:
RewriteRule ^(index\.html)?$ http://www.yoursite.com/$1 [R=301,L]
The specific pattern above of index.html followed by a ? will match yoursite.com/index.html OR yoursite.com/, but nothing else.
A ? following a character or pattern specifies 0 or 1 of the immediately preceding characters or sets of characters.
() create and store a variable.
\. matches a single .(dot) not 'any character, except the end of a line'
Hope this helps.
Justin
BTW for the httpd.conf file instead of the .htaccess you will need to chage the left side to ^/(index\.html)?$
I swapped the rule to the following in .htaccess:
Options +FollowSymLinks
RewriteEngine on
# redirect all valid domain aliases to the www form
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule ^(index\.html)?$ [mysite.com...] [R=301,L]
With this script, I get a "500 Internal Server Error". Also, FWIW, I tried the following simple .htaccess string:
redirect 301 /index.html [mysite.com...]
This seemed to work just fine...except when I check the header status. For the IP address it showed "301 moved permanently"...great! For the main domain (www.mydomain.com), it also showed "301 moved permanently"...not great :-)
Dave
I found a small syntax issue with what I had typed. Here's what I have in .htaccess now, and the results:
Options +FollowSymLinks
RewriteEngine on
# redirect all valid domain aliases to the www form
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule ^(index\.html)?$ [mysite.com...] [R=301,L]
It does not redirect you from the IP addy to www.mysite.com in the URL bar of your browser, but it does report a "301 permanently moved" when I check the header. I wonder if that will suffice for the search engines, so they don't think my IP and domain are two different sites (trying to dodge the dupe content problem I seem to have with Y!, since they have indexed my site both ways for some reason).
Dave
Now, if Y! will get me out of the dupe content penalty box, I can see how many folks use Y! for my niche market :-)
Thanks again!
Dave