0

I have changed my photo gallery to a subdomain of my web hosting account.

Since google is still referencing the old links to my pictures, I want to do a 301 redirect with htaccess. In the 301 redirect I think the best way is to search incoming URL for specific string in old link and if found then just append photos to link as subdomain.

eg incoming URL - http://www.MYDOMAIN.com/photography-...y/12345_crABCD

check incoming URL's for string "photography-gallery" if found then 301 rewrite URL by appending subdomain photos to URL

photos.MYDOMAIN.com/photography-gallery/12345_crABCD

I also tried this redirectin htaccess to just go to my domain if string found and it did not do anything

redirect 301 /photography-gallery/ http://www.MYDOMAIN.com/

Can someone help with writing the expression for this htaccess redirect or rewrite? Thanks

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
user2280480
  • 1
  • 1
  • 1

2 Answers2

0

You will want to look into .htaccess Rewrites, which will allow you to conditionally redirect.

You will want to check if the url matches /photography-gallery/ at any point, and then redirect that off to the subdomain.

RewriteRule ^\/photography-gallery\/([0-9a-z_A-Z]+)\/?$ http://photos.domain.com/$1 [R=301,L]

The above should do it for you. Also, take a look at using Google Webmaster Tools for ensuring that paths are redirecting correctly etc.

  • Thanks. I will give it that a try. I also tried another way for redirect and this seems to work too RedirectMatch 301 ^/photography-gallery/(.*)$ http://www.MYDOMAIN.com/ – user2280480 Apr 14 '13 at 21:34
  • wow that is great link on to know. its like learning new language and that link is like rosetta stone. thanks – user2280480 Apr 14 '13 at 21:43
0

If you want to redirect the same URL to another domain, you can use this simple RewriteRule

RewriteEngine on
RewriteRule ^photography-gallery/.*$ http://photos.mydomain.com/$0 [R,L]

When everything works as you expect, you can change R to R=301.

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Ok I tried the 2 codes given and none of them work. I then made some minor tweaks and tried it again and it still did not redirect correctly. Could the special characters #,! in the original URL be messing up the redirect? This is code I tweaked and used RewriteEngine On RewriteRule ^/Photo-Gallery/(.+)$ http://photos.MYDMAIN.com/$1 [R=301,L] I tried this original URL to my gallery http://www.MYDOMAIN.com/XYZ/ABC/28346798_nGctqv#!i=2399742179&k=MbKVDWq and it RETURNS this value in URL and went to my homepage instead of correct link http://www.MYDOMAIN.com/#!i=2399742179&k=MbKVDWq – user2280480 Apr 15 '13 at 05:53
  • @user2280480 Please copy the rule as I wrote it. There is *no* leading slash in the rule pattern. And please don't use `R=301`, unless the rules work as they should. – Olaf Dietsche Apr 15 '13 at 06:16