![]() |
redirecting to subdomain via htaccess
Hello everyone! :-)
Question. I have over 2000 URLs I'm trying to successfully 301 redirect to subdomains using the root htaccess file. Code:
domain.com/same/NAME to NAME.domain.comInstead of writing each URL line by line: Redirect 301 /same/1 http://1.domain.com Redirect 301 /same/2 http://2.domain.com Redirect 301 /same/3 http://3.domain.com I was thinking is it possible to redirect it all using 1 line, like: Code:
Redirect 301 /same/$1 http://(.*).domain.com |
It might not be as simple as copy/paste but a starting point might be along the lines of:
htaccess Code:
|
Worked a treat. Cheers Salathe.
|
Code:
RewriteRule ^sample/(.*)/ http://$1.domain.com [R=301,L]So domain.com/sample/page and domain.com/sample/page/ both redirect to the same page. Is there anyway to merge those two lines? |
Since we're afforded the yumminess that is regular expressions, we can simply specify that the trailing slash is optional with the question mark character (
?). Also, will the varying values only ever be numbers? Or, would you like to only capture what's between sample/ and the next forward slash (if there is one)? I'm just asking because it's better to make the matching expression as specific as possible! At the moment sample/my/sub/domain.html would try to redirect to http://my/sub/domain.html.domain.com which I'm fairly sure you don't want.Anyhow, to answer your question: RewriteRule ^sample/(.*)/? http://$1.domain.com [R=301,L] |
There is a mix of letters numbers and -.
When going to domain.com/sample/page/ it redirects to: page.com/.domain.com umm |
| All times are GMT. The time now is 06:38 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0