Welcome to WebmasterWorld Guest from 54.147.63.124

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Remove superflous directory which has same name as domain

     
4:01 am on Sep 25, 2012 (gmt 0)

New User

5+ Year Member

joined:Apr 9, 2006
posts: 11
votes: 0


I want to redirect http://example.com/example.com/index.htm to http://example.com/index.htm

I use htaccess to host multiple parked domains on one account...

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^/*example\.com/ example.com%{REQUEST_URI} [L]

I place all the domain files in the directory "example.com" but I screwed up somehow and now Google sometimes points to the directory "example.com"

I tried the following...

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

But it does not work... I really have no idea what I am doing, so help would be appreciated.

[edited by: phranque at 6:04 am (utc) on Sep 25, 2012]
[edit reason] use example.com please [/edit]

6:15 am on Sept 25, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12714
votes: 244


Looks like you haven't been around in a while-- unless you're a very devoted lurker-- so start by reading the thread about using example.com. Look at your own post and you will see the point.

A RewriteRule can only see the "body" of an URL. Anything involving domains and/or queries has to go into a RewriteCond.

But before you do too much work, check with your host. A lot of them will do this kind of routine redirection for you, so you don't have to mess with htaccess if it alarms you.
6:21 am on Sept 25, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10544
votes: 8


it does not work...

what was the status code?

THE_REQUEST is going to begin with the HTTP Request method such as GET or POST so your RewriteCond will always be false.
in your case the RewriteCond is probably unnecessary.

what is your canonical hostname?
in your problem statement you use example.com yet you use www.example.com in your RewriteRule.
6:39 am on Sept 25, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Replacing
^(www\.)?
in the condition with
^[A-Z]{3,9}\_
where
_
is a space should get you closer.

You should not be redirecting to a named index.html file. The canonical URL for the site root ends with a trailing slash.
7:00 am on Sept 25, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12714
votes: 244


Oops. My bad. I didn't read your question closely enough or I'd have seen that the problem is duplication. Somewhere in the past you goofed in a redirect and came out with something like

www.example.com/example.com/index.html

Have I got that right?

If so, you don't need a condition at all. The element "example.com" will never be part of an URL-- other than in the "domain" slot, where the RewriteRule can't see it. And unlike "index.html" or equivalent it will never be supplied by anything operating behind the scenes, so you don't need to look at THE_REQUEST. When you redirect

^example\.com(/(index\.html)?)?
(that is, "www.example.com/example.com/" possibly ending in directory slash followed by an explicit "index.html")

to

http://www.example.com/ [R=301,L]

the "index.html" part will quietly disappear if it was there, and your domain name-- the real one-- will get canonicalized. So that's three birds with one stone ;)
6:43 am on Sept 26, 2012 (gmt 0)

New User

5+ Year Member

joined:Apr 9, 2006
posts: 11
votes: 0


Thank you phranque & lucy24, I will remove the condition and report back.

I've been letting my site run on auto pilot, but now it has 10,000 visitors a day I figured it is time to earn some adsense revenue off it.
9:46 pm on Sept 26, 2012 (gmt 0)

New User

5+ Year Member

joined:Apr 9, 2006
posts: 11
votes: 0


This works, for everything except my domain name. If I try a random example...

RewriteRule ^fred\.com/(.*)$ http://www.example.com/$1 [R=301,L]

Then http://www.example.com/fred.com/puzzles is rewritten as http://www.example.com/puzzles

If I try my domain name

RewriteRule ^example\.com/(.*)$ http://www.example.com/$1 [R=301,L]

Then http://www.example.com/example.com/puzzles remains unchanged... Help?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members