.htaccess question

Hello,

I tried to resolve my problem with the support of google search, but I had no chance. I just need to transfer
everything inside ( htttp//:subdomain.mydomain.com/en ) to ( htttp//:www.mydomain.org/data/en ), how can I do that ?

Thanks in advance for your help.

Hi,

As you would likely want to save your Search Engine indexing then consider the following:

  • If you have access to the main apache.conf file then you can define an Apache RewriteMap that will permanently redirect all you links in [noparse]http//:subdomain.mydomain.com/en[/noparse] to [noparse]“http://www.mydomain.org/data/en”]www.mydomain.org/data/en[/noparse]. This cannot be done using .htaccess
  • If you only have access to .htaccess, then you will need to use 301 (Permanent Redirects) using mod_rewrite
  • You should keep both domains until you have all of you rewriting completed. You want to make sure that the search engine crawlers find a real site (not a 404 error), so don’t cancel your old site until the redirects are complete and tested.
  • You also will need to create a new apache virtual host with all of your [noparse] http//:subdomain.mydomain.com/en[/noparse] settings. If desired you can keep the same location for your new versus old site, you just have to ensure that you set the correct path to the files.
  • Finally you will need to set new DNS, A records your public DNS that will point to your new site.

Regards,
Steve

@ServerStorm; I’m not sure why you would suggest a RewriteMap over a RewriteRule? The latter is a lot easier, since it’s just a few lines of code that can be placed in a .htaccess


RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\\.mydomain\\.com$ [NC]
RewriteRule ^en(/.*)?$ http://www.mydomain.com/data/en$1 [L,R=301]

With a RewriteMap you’d have to list all individual redirects, which is a lot more work.

I agree with all your other points though! :slight_smile:

[SIZE=2][FONT=verdana]Hi ScallioXTX,

I recommend the rewrite map as it is easier to manage if the rerouting is complicated or there are an extensive amount of links; if the full site that the OP is moving is large or complicated then it may be the best option. If the OP does not have a lot of links to reroute or does not have access to their apache.conf files then as I also suggested (just not as clearly as you in my 2nd point :blush:) the second option is to do as you outline; use a [/FONT][/SIZE][COLOR=#464646][FONT=Helvetica Neue][SIZE=2][FONT=verdana]RewriteRule.

Regards,
Steve[/FONT][/SIZE]

[/FONT][/COLOR]

Hello and thanks for you both!!
In fact I have tried the following code

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^en(/.*)?$ http://www.mydomain.com/data/en$1 [L,R=301]

in the .htaccess file in httpdocs folder in the subdomain hosting, nothing happened, why ?

I tried also a sample code :

Redirect 301 /en http://www.mydomain.com/data/en

But also I got error links…