Google has picked up a few of my subdomains but is using domain.com/abc to link to them. How can I rewrite these back to abc.domain.com to avoid duplicate content issues?
Thanks - that nearly works. But it messes up the rest of the URL. I need to change www.domain.com/subdomain/search+term to subdomain.domain.com/search+term Code (markup):
How does the rest of it look like? I have the very same setup on one of my site's subdomain and it works perfectly.
Here's my original subdomain htaccess: RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L] Code (markup): It simply changes /index.php?s=search+term to /search+term When I added Redirect 301 /abc http://abc.domain.com Code (markup): it was doubling up everything after the last slash. e.g http://www.domain.com/subdomain/search+term turned into: http://subdomain.domain.com/search+term?s=search+term
Well then remove all of the rewrites in the domain.com/subdomain/, keep only the 301 redirect. The rewrites won't be used there anyway.
But that's exactly why I've got that stuff in the original htaccess... I want to avoid index.php?s=bla+bla+bla and just have /bla+bla+bla ----- I found this in another forum, I have absolutely no idea what's going on, but it works. Can somebody check to make sure that all the 301s etc are correct? I am WAY out of my depth with mod_rewrite (obviously!) htaccess for domain.com/subdomain: RewriteEngine On #my original rewrite to make the url a bit prettier RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L] #new stuff to rewrite directory to subdomain RewriteRule !\..{3,4}$ - [C] RewriteCond %{HTTP_HOST} !^subdomain RewriteCond %{REQUEST_URI} !^.*/$ RewriteRule ^(.+)$ http://subdomain.domain.com/ [R=301,L] RewriteCond %{HTTP_HOST} !^subdomain RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [R] Code (markup): Can anyone tidy this up or improve on it?
You don't need the rewrite code in the old directory. Everything (/bla+bla+bla) will be redirect to the new subdomain, place the rewrite code there.
There has only ever been one subdomain directory - there is no 'old' directory. I created the subdomain in cPanel, which creates a directory domain.com/subdomain. domain.com/subdomain/.htaccess is the only htaccess file in use. If I remove the original rewrite from it, my site will break.
I still don't really understand what you're talking about domain.com/subdomain/this+is+a+search and subdomain.com/this+is+a+search both work at the moment. All I need to do, is make it so domain.com/subdomain/this+is+a+search 301s to subdomain.com/this+is+a+search to avoid duplicate content issues.
Nup. that doesn't work. I'll just stick with this unless somebody can clean it up a bit. RewriteEngine On #my original rewrite to make the url a bit prettier RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L] #new stuff to rewrite directory to subdomain RewriteRule !\..{3,4}$ - [C] RewriteCond %{HTTP_HOST} !^subdomain RewriteCond %{REQUEST_URI} !^.*/$ RewriteRule ^(.+)$ http://subdomain.domain.com/ [R=301,L] RewriteCond %{HTTP_HOST} !^subdomain RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [R] Code (markup):
Your first block of code rewrites /stuff to index.php?s=stuff. Your second block of code then redirects whatever the current request is (now, after the rewrite, index.php?s=) to the subdomain. You just need to change the order round - do the redirect first, then the rewrite: Redirect 301 /abc http://abc.domain.com RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ index.php?s=$1 [QSA,L] Code (markup):
I tried that, it nearly works, but the url gets screwed. e.g http://www.domain.com/subdomain/my+search+term goes to: http://subdomain.domain.com/my+search+term?s=my+search+term Code (markup): Any ideas? I'm happy to use the messy htaccess that I posted above, it works - but I'm pretty sure it's not an elegant way to do it.
RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ RewriteRule ^(.*)$ http://abc.domain.com/$1? [R=301,L] RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/.]+)/?$ index.php?s=$1 [QSA,L] Code (markup): I dunno how to stop it preserving the query string when using mod_alias, but hopefully that should do it using mod_rewrite.