Forum Moderators: phranque

Message Too Old, No Replies

a .htaccess question (redirection)

         

effisk

11:01 pm on Aug 30, 2005 (gmt 0)

10+ Year Member



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:

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.example.net/?-acheter
(this one is redirected ok)

-http://surf.example.net/index.php?-acheter
(this is the same page - slightly different url - redirection does not work).

[edited by: jdMorgan at 11:47 pm (utc) on Aug. 30, 2005]
[edit reason] Examplified. [/edit]

jd01

1:02 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

Hmmm... not the technically correct usage of QSA, but there have been times when I have needed to use it in this type of situation before.

Just one thing, I cannot use mod_rewrite (deactivated by my provider).

Not sure what you mean by this, because the code you provided as partially working is mod_rewrite?

Hope this helps.

Justin

jdMorgan

1:08 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no reason that code should not work for the /index.php file -- As written, it should redirect requests for *any* page to the same page in the main domain.

Two things that might cause trouble:

1) You have other RewriteRules or Redirects that are interfering.

2) You forgot to flush your browser cache (Temporary Internet Files) before testing.

Comment: I suggest that you do not end-anchor the domain name pattern. Doing so will cause the rule to fail if a port number is appended, e.g. sub.domain.com:80/index.php

It should read:


RewriteCond %{HTTP_HOST} sub\.domain\.com [NC]

If you feel you must end-anchor it, then allow for an optional port number:

RewriteCond %{HTTP_HOST} sub\.domain\.com(:[0-9]{1,5})?$ [NC]

However, this change won't affect the problem you're reporting here.

Jim

effisk

10:30 am on Aug 31, 2005 (gmt 0)

10+ Year Member



Hi guys and thanks for your replies.

jd01 I tested your solution with no luck. It makes no difference at all.

My provider told me mod_rewrite was disabled in my configuration so I'm not sure what's going on here.

jdMorgan here is the whole content of my .htaccess:
-------------------------
# Hotlink control
SetEnvIfNoCase Referer "^http://sub.domain.com" local_referal
SetEnvIfNoCase Referer "^http://www.domain.com" local_referal
SetEnvIfNoCase Referer "^http://www.newdomain.com" 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

RewriteEngine On

RewriteCond %{HTTP_HOST} sub\.domain\.com(:[0-9]{1,5})?$ [NC]
RewriteRule ^(.*)$ [newdomain.com...] [R=permanent,L]
------------------------
I tried with several browsers, some of which I never used for that site and with cache disallowed.

Is there anything that could interfere with or cancel the .htaccess actions?

I'm a bit lost here, most of my pages have disappeared from google's index since the change of domain name. Those that have not dissapeared are those not accessible via the index.php url.

jd01

5:48 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure what's going on here.

Me too... This is mod_rewrite:

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

Please, confirm you can and are using this code with some success, otherwise I am not sure of a solution - If mod_rewrite is "off" or not loaded, the above code should not work at all.

Justin

effisk

8:26 am on Sep 1, 2005 (gmt 0)

10+ Year Member



I just removed the code and typed sub.domain.com -> no redirection
Added it again in .htaccess and it is being redirected again so it makes no doubt.
I am using the exact code you mention in your last message.

But redirection of index.php still does not work.