views:

594

answers:

3

ok so heres the scenario:

i got a blog on the root directory of my host then i hosted some app on a subfolder named fsGallery. now, i bought a new domain for my blog and another domain for my app. ii would like to know the proper htaccess 301 redirects in order for me to redirect the old directories to their respective new domains

here's a sample dir structure:

root/
  /app
  [blog]

trying to: redir /app to newdomainforapp.com redir [blog] to newdomainforblog.com

also, originally, my app used to accept url parameters like this: app/user/1234567

so i would also like to: redir /app/user/{dynamic int parameter} to newdomainforapp.com/profile/{dynamic int parameter}

can anyone help me plox?

A: 

It seems RewriteRules should work fine.

RewriteEngine on
RewriteRule ^/?app/user/([0-9]+) http://newdomainforapp.com/profile/$1 [R=301,L]
RewriteRule ^/?app(/(.*))?$ http://newdomainforapp.com/$2 [R=301,L]
RewriteRule ^/?(.*) http://newdomainforblog.com/$1 [R=301,L]

You'll probably need to play around with the groups to redirect articles properly.

outis
worked like a charm! thanks a bunch!
VeeBee
I actually like David's suggestion better--did you try that?
outis
+1  A: 

Possibly not programming-related, but anyway: the proper way to do this is in the virtual host configuration file (i.e. in the <VirtualHost *:80> ... </VirtualHost> section), not in an .htaccess file. The directives to use are

 RedirectMatch permanent /app/user/([0-9+]) http://newdomainforapp.com/profile/$1
 Redirect permanent /app http://newdomainforapp.com
 Redirect permanent / http://newdomainforblog.com
David Zaslavsky
i was only being hosted by my friend in a subdomain previously so i don't have any access to server specific files. but anyways thanks for this also. it might come in handy now that i have my own host.
VeeBee
Redirect and RedirectMatch work in .htaccess. Check their documentation: http://httpd.apache.org/docs/1.3/mod/mod_alias.html
outis
@outis: True, but still, the proper way to use them is to put them in the main server configuration file. In fact, putting directives in the vhost config file is nearly always preferably to using .htaccess files.
David Zaslavsky
A: 

hello... i want to learn redirect

ex.

i have a website with 2 language page

like http://stackoverflow.com/en ==>> english language

http://stackoverflow.com/id ==>> indonesian language

now, if i open from US IP will redirect to http://stackoverflow.com/en

& if i open from Indonesian's IP will redirect to http://stackoverflow.com/id

like google.com if i open will redirect to google.co.id but google using redirect domain

how to redirect to different page or directory ??

please help me :)

crashblack