Forum Moderators: phranque

Message Too Old, No Replies

301 www.example.com./ to www.example.com/

Remove dot before slash

         

LunaC

2:06 pm on Sep 26, 2006 (gmt 0)

10+ Year Member



Yup, back here again with another 301 question. I just found a pile of scrappers linking to one of my sites with a dot after the com and before the slash.
ie. www.example.com./

Headers are returning a code 200, which is not good at all. That just seems way to open for dupe content issues.

I've searched all over and can't find any reference to this other than that it's "a good way to #@*$ competitors". Hmm, not good news.

So how can I add a 301 redirect to properly to remove the dot?

(Sorry I keep asking questions. I do try, but I just can't grasp this stuff enough to write it myself. I've read tutorials, lurk here making notes.. it just seems my mind is not built to process .htaccess. I really do appreciate all the help!)

jdMorgan

7:01 pm on Sep 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The commonly-used code to redirect non-canonical domain names can be modified to fix this problem, too.

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

This adds a test to the hostname check to include a possibly-appended (and permissible) port number. However, if anything else is present (like a trailing period), the redirect will be invoked.

Otherwise, if you don't wish to allow the port number, you can just end-anchor the hostname:


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

In both cases, the first RewriteCond line is only needed if your site has its own unique IP address, and is accessible by true HTTP/1.0 clients. It is not needed on name-based virtual server (shared hosting) accounts, which share IP addresses among several sites and are therefore not accessible to true HTTP/1.0 clients.

Jim

LunaC

7:54 pm on Sep 26, 2006 (gmt 0)

10+ Year Member



Thanks for both the examples and the explanation. It works perfectly.

AndyA

9:49 pm on Sep 26, 2006 (gmt 0)

10+ Year Member



Thanks for posting this issue, LunaC. I checked my logs and sure enough scrapers have done the same thing to my site!

But not any longer.

Geez, and I wondered why Google thought I had duplicate content...

sfseo

9:34 am on Sep 28, 2006 (gmt 0)

10+ Year Member



I've got a similar problem. How can I remove the /? mark.

http://www.example.com/?=DSL
http://www.example.com/?=BED

Those are not pages in our website but Yahoo indexed them as duplicates of our home page! I tried creating a 404 page but was not able to do so using Front Page. The next thing I tried is to use a robots.txt file to Disallow: /?

I need some help. any suggestions would be greatly appreciated. thanks! Chris.

[edited by: jdMorgan at 11:34 pm (utc) on Sep. 28, 2006]
[edit reason] Example.com [/edit]

LunaC

12:49 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



sfseo, I had that problem before to. Here's what jdMorgan wrote, and it is working great on all my sites.

If you have no place at all that uses query strings in your sites, this works:

#remove useless ?junk 
RewriteCond %{THE_REQUEST} [?]
RewriteRule ^(.*)$ http://example.com/$1? [R=301,L]

If you have a few files that need the query string (search, a form etc.), here's how to do that:

#remove useless query strings, keep needed ones 
RewriteCond %{THE_REQUEST} [?]
RewriteCond %{REQUEST_URI} !^/path-to/file-excluded-from-rule/filename\.pl$
RewriteCond %{REQUEST_URI} !^/another/excluded/file\.php$
RewriteRule ^(.*)$ http://example.com/$1? [R=301,L]

As I said above, I'm no expert (pretty much a lost newbie at this), but this is working for me.

Be sure to clear your cache and test the headers after any change. If you use Firefox, the LiveHTTPHeaders extension works great.

Edit:
The forum was removing the space between }!
Be sure to check and edit that back in if you try this code.

[edited by: LunaC at 1:06 pm (utc) on Sep. 28, 2006]

sfseo

10:06 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



If I want those queries to go to a 404 page do I just put 404 after R=? For Example:

#remove useless?junk
RewriteCond %{THE_REQUEST} [?]
RewriteRule ^(.*)$ http://example.com/$1? [R=404,L]

Thanks guys I'm new to this.

[edited by: jdMorgan at 11:34 pm (utc) on Sep. 28, 2006]
[edit reason] Example.com [/edit]

sfseo

12:46 am on Sep 29, 2006 (gmt 0)

10+ Year Member



Luna/Jd:

I tried that and it didn't work. Is this the proper way to write it?

RewriteCond %{HTTP_HOST}?
RewriteRule ^(.*)$ http://example.com/$1? [R=301,L]