Forum Moderators: phranque

Message Too Old, No Replies

Redirect, Root only

         

Ahkamden

3:34 am on Sep 4, 2009 (gmt 0)

10+ Year Member



I've been scouring webmasterworld and googling trying to find out this answer, but no luck so far.

Is there a way to redirect only queries for root index? IE www.example.com. And redirect it to www.example1.com.

If someone goes to www.example.com/1 it should still process through original domain. I'm doing this for a url shortening service. I want the shortened urls to redirect properly and script to still work. But for any root index requests, I would like forwarded to main domain.

I tried:
RewriteRule ^index\.htm$ http://example.com/index.php [R=301,L]

It doesn't even error out, just goes to current blank index page.

jdMorgan

1:20 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule looks at the requested URL-path, not at a filepath. So your rule will only work if "http://www.example/com/index.htm" is requested by the client. It won't work if the request is for "www.example.com/".

So, you can change it to either


RewriteRule ^$ http://example.com/index.php [R=301,L]

-or-

RewriteRule ^(index\.htm)?$ http://example.com/index.php [R=301,L]

(The second variant will redirect requests for either "/" or "/index.htm")

Also, be aware that this is an extrernal redirect, and that search engines will likely 'update' their search results to show your "home page" as "index.php" in the search results. Is that really what you want?

Jim

Ahkamden

1:25 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



Thanks jd! And Ack! no that's not what I want. I just want to repoint any requests to new domain, without an issue like Google seeing it as index.php.

Is there another way to possible do this? Or am I better of with just sticking a static html page there?

jdMorgan

2:31 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are many ways to do many things, but it really depends on what you want to do.

I think that what you want is more like:


RewriteRule ^(index\.htm)?$ http://www.example1.com/ [R=301,L]

Jim

Ahkamden

12:40 am on Sep 5, 2009 (gmt 0)

10+ Year Member



I know, that's what makes me crazy. And I know just enough to be dangerous.

So this won't affect SEO on the domain it is redirected to right? For the site that is doing the redirect, I could careless about SEO factor.

jdMorgan

1:08 am on Sep 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it will "affect SEO" because the old URL now becomes the new URL. Eventually, all ranking 'power' of the old URL will be passed through the 301-redirect to the new URL.

Jim

Ahkamden

2:36 am on Sep 5, 2009 (gmt 0)

10+ Year Member



I'm almost there. I used the RewriteRule ^(index\.htm)?$ [example1.com...] [R=301,L]

So now when I goto [example1.com...] it does redirect me to example2. But if I goto just [example1.com...] it shows blank page.

I really appreciate all of the help Jim.

jdMorgan

4:18 am on Sep 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's strange. Make sure the code is in a .htaccess file in the same directory where a request for 'example1.com/" should resolve to, and make sure there are no other RewriteRules or mod_alias directives ahead of this rule that could 'catch' those requests and divert them before the redirect executes.

Jim

Ahkamden

5:30 am on Sep 5, 2009 (gmt 0)

10+ Year Member



Maybe it was cache in my system? But wasn't working earlier, is now working perfectly.

Redirects seen to work without issue, and I can access to make new directs. If you try to access root, you get redirected to correct domain.

You're a genius! I was a paying member for awhile, but dropped out due to not being active webmaster. Will look into reactivating my membership. Can't say thanks enough Jim!