iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2005, 03:16 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default a .htaccess question (redirection)

Hi everyone,

I have a tricky (at least to me) problem with htaccess. Here it is:

I own sub.domain.com on which I have a website.
I have recently bought newdomain.com to to use instead of sub.domain.com for this website.

The site is still hosted at the same place, so currently pages are available thru both URLs.

I want to permanently move the site from the subdomain to the new domain.

My pages currently are:
sub.domain.com/?-name-of-page
also accessible thru
sub.domain.com/index.php?name-of-page

I currently use these lines of code in my .htaccess file for the redirection:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]
It does the trick for sub.domain.com/?-name-of-page (it redirects to newdomain.com/?-name-of-page) but it does not work for sub.domain.com/index.php?-name-of-page

hom come? What did I do wrong and what should I change?

I don't know much about .htaccess redirection, and I could not find any info for this specific problem on the internet, so if someone has any knowledge in that field, please enlighten me.
Just one thing, I cannot use mod_rewrite (deactivated by my provider).

example of the problem here:

-http://surf-bodyboard.effisk.net/?2005/03/15/1-acheter
(this one is redirected ok)

-http://surf-bodyboard.effisk.net/index.php?2005/03/15/1-acheter
(this is the same page - slightly different url - redirection does not work).
Reply With Quote
  #2 (permalink)  
Old 08-29-2005, 03:50 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

adding these lines below the existing ones makes no difference:

Code:
RewriteCond %{HTTP_HOST} sub\.domain\.com/index\.php$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]
Reply With Quote
  #3 (permalink)  
Old 08-29-2005, 09:51 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

Maybe I should have posted this in the SEO forum...
Reply With Quote
  #4 (permalink)  
Old 08-30-2005, 07:01 PM
incrediblehelp's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jan 2004
Location: Live in Cincy Now
Posts: 7,573
incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4
Default

So this is the code and it is not working:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://surf-bodyboard.effisk.net/ind...3/15/1-acheter
RewriteRule (.*) http://www.surf-blog.net/?2005/03/15/1-acheter/$1 [R=301,L]

?

I would also try posting here:

http://www.webmasterworld.com/forum92/page116.htm
Reply With Quote
  #5 (permalink)  
Old 08-30-2005, 08:03 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

thanks for your reply.

I tried the code you osted, it does nothing. No redirection at all.

I tried my luck at WMW...

thanks.
Reply With Quote
  #6 (permalink)  
Old 08-30-2005, 11:10 PM
incrediblehelp's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jan 2004
Location: Live in Cincy Now
Posts: 7,573
incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4
Default

Weird, dont know sorry.
Reply With Quote
  #7 (permalink)  
Old 08-31-2005, 12:43 PM
WebProWorld 1,000+ Club
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 1,782
cyanide RepRank 0
Default

I don't know why you are using a re-write condition. A simple re-direction should work.

Code:
Permanent 301 / http://www.newdomain.com
You should also create a custom 404 error page on the sub-domain, which contain links to the new domain.

Web Hosting | Webmaster Help
Reply With Quote
  #8 (permalink)  
Old 08-31-2005, 01:03 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

Hi.
Quote:
Originally Posted by cyanide
I don't know why you are using a re-write condition. A simple re-direction should work.
Code:
Permanent 301 / http://www.newdomain.com
Sorry my original post wasn't very clear:
sub.domain.com and newdomain.com are the same site. hosted at the same place.
newdomain.com/index.php is not a copy of sub.domain.com/index.php, it is the same page.

because of the above reason, your suggestion won't work. It will create a loop and end up telling the visitor that the maximum redirection limit has been hit and the page won't be served.
Reply With Quote
  #9 (permalink)  
Old 09-01-2005, 04:39 PM
WebProWorld Pro
 
Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

What about adding something like the quick, dirty, and unrefined code below to index.php:

<?
$hostname =getenv('HTTP_HOST');

$page= getenv("REQUEST_URI");

$new_destination="http://yournewdomain".$page;

if (stristr($hostname,"yoursubdomain")){
header("HTTP/1.1 301 Moved Permanently");
header("Location: $new_destination");
exit();
}
?>
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #10 (permalink)  
Old 09-01-2005, 07:15 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

Quote:
Originally Posted by steve0
What about adding something like the quick, dirty, and unrefined code below to index.php:

<?
$hostname =getenv('HTTP_HOST');

$page= getenv("REQUEST_URI");

$new_destination="http://yournewdomain".$page;

if (stristr($hostname,"yoursubdomain")){
header("HTTP/1.1 301 Moved Permanently");
header("Location: $new_destination");
exit();
}
?>
believe it or not, it has no effect! at all

I don't get it.
Reply With Quote
  #11 (permalink)  
Old 09-01-2005, 10:31 PM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default A working sample...

Here is a working sample:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^toolbarn.*
RewriteRule ^(.*) http://www.toolbarn.com/$1 [R=301,L]
That redirects toolbarn.com to www.toolbarn.com for us. In your case, it could be modified to the following and should work:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.*
RewriteRule ^(.*) http://www.newdomain.com/$1 [R=301,L]
Is that of any help?

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #12 (permalink)  
Old 09-01-2005, 10:36 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default Re: A working sample...

Quote:
Originally Posted by brian.mark
Is that of any help?
No. It has the same effect as the code proposed previously. Does the job for urls without the index.php only.



*crying of despair*
Reply With Quote
  #13 (permalink)  
Old 09-01-2005, 10:44 PM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default Do you have...

Do you have any other lines in the .htaccess file before these? These should be the first lines of your file for them to work properly.

If you'd like me to really dig, pm me for an email address that you can send login info to. You can delete / change the login when I'm done. I'm just really curious and would love to see it work right.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #14 (permalink)  
Old 09-01-2005, 11:03 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default Re: Do you have...

Quote:
Originally Posted by brian.mark
Do you have any other lines in the .htaccess file before these? These should be the first lines of your file for them to work properly.
Ok here's the whole content of the file:


RewriteEngine On

RewriteCond %{HTTP_HOST} sub\.domain\.com(:[0-9]{1,5})?$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]


# Hotlink control
SetEnvIfNoCase Referer "^http://sub.domain.com" local_referal
SetEnvIfNoCase Referer "^http://www.newdomain.com" local_referal
SetEnvIfNoCase Referer "^http://www.other-domain.net" local_referal
SetEnvIfNoCase Referer "^$" local_referal

<FilesMatch "\.(gif|jpe?g|png)$">
Order Deny,Allow
Deny From All
Allow from env=local_referal
</FilesMatch>

errordocument 403 /403.html
errordocument 404 /404.html

I also tried to only leave the RewriteEngine rules and remove the rest, no difference.
Quote:
Originally Posted by brian.mark
If you'd like me to really dig, pm me for an email address that you can send login info to. You can delete / change the login when I'm done. I'm just really curious and would love to see it work right.
So do I. :/

I'm not sure I can grant you access to my ftp. I have limited rights to this account.
Reply With Quote
  #15 (permalink)  
Old 09-01-2005, 11:51 PM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default Well...

Well... if I'm reading this part right

Code:
sub\.domain\.com(:[0-9]{1,5})?$
that is saying it's looking for any port (up to 5 digits) and a ? right after it. Have you tried getting rid of the ? in that particular line? This is a real odd one... most people don't bother with the port directives since 80 is covered by default and they don't run Apache on any other ports.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #16 (permalink)  
Old 09-02-2005, 04:41 AM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

If I remove the ? it doesn't redirect any page anymore.

RewriteEngine On
RewriteCond %{HTTP_HOST} sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]

has the same effect as what I currently have.
Reply With Quote
  #17 (permalink)  
Old 09-02-2005, 11:49 AM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default Have you considered...

Have you considered redirecting index.php to / at all? That could solve the problem here as well as avoid duplicate content in the search engine indexes. Otherwise, I'm totally drawing a blank.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #18 (permalink)  
Old 09-02-2005, 12:17 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default Re: Have you considered...

Quote:
Originally Posted by brian.mark
Have you considered redirecting index.php to / at all?
Actually no I haven't. How can I do that? Using the .htaccess file?

thanks for the time you spend on this.
Reply With Quote
  #19 (permalink)  
Old 09-02-2005, 12:28 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

I just tried:

Redirect /index.php http://www.newdomain.com/

no success.
Reply With Quote
  #20 (permalink)  
Old 09-02-2005, 12:42 PM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default Try to same domain...

Try it to the same domain.

Code:
redirect 301 /index.php http://subdomain.olddomain.com/
Or, use a rewrite.

Code:
RewriteEngine On
RewriteRule ^index.php(.+)$ http://subdomain.olddomain.com/$1
I'm joining you... banging head on desk... "This shouldn't be that hard of a problem!!!"

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #21 (permalink)  
Old 09-02-2005, 01:11 PM
effisk's Avatar
WebProWorld Pro
 
Join Date: May 2004
Location: Biarritz, France
Posts: 156
effisk RepRank 0
Default

I tried both, first along with the rest of my code, then on its own in the .htaccess.

Same results as before. There must be some other parameter that has an impact outside of this htaccess file, but what, and why?

I've cleaned up the web from links to pages with index.php, I guess I'll just wait till SE stop indexing these pages and I'll leave the htaccess as is.

I wrote to my provider about this problem, I'll keep you posted if I have a reply.

This is very weird but I'm sure it's something simple that we haven't thought of.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:40 AM.



Search Engine Optimization by vBSEO 3.3.0