vexx Posted August 20, 2012 Share Posted August 20, 2012 Hey guys, I'm in a bit of a situation. I want to change my rewrite rules for a folder to a subdomain and then redirect old rules to new ones (for SEO). So basically I have this: RewriteEngine On RewriteBase / RewriteRule ^news/index([0-9-]+)\.html$ index.php?page=pressrelease_homepage&pn=$1 RewriteRule ^news/$ index.php?page=pressrelease_homepage RewriteRule ^press/([a-zA-Z0-9-]+)-([0-9-]+)\.html$ index.php?page=pressrelease_page&id=$2 I want to rewrite everything www.site.com/news to press.site.com and everything /press/ to press.site.com. After I do this, I want to redirect all old links to the new subdomain links. I tried several methods but I wasn't very successful. Any help will be greatful! Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/ Share on other sites More sharing options...
premiso Posted August 20, 2012 Share Posted August 20, 2012 In the code you posted, I do not see you redirecting to the subdomain, if you tried that post the code you tried so we can maybe see where you went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1370973 Share on other sites More sharing options...
vexx Posted August 21, 2012 Author Share Posted August 21, 2012 in the code I posted I didn't try..it's just the original code...I did have some attempts based on some suggestions I had but with no success. It's worth mentioning that I'm in my learning stage now and I would definitely love some help in this particular case tnx! Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1371027 Share on other sites More sharing options...
vexx Posted August 21, 2012 Author Share Posted August 21, 2012 so..if anyone can help..or guide me ...I really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1371205 Share on other sites More sharing options...
handlegeek Posted August 28, 2012 Share Posted August 28, 2012 If you can give couple of examples of redirect you want to do - it would be better. Both /press and /news to press.site.com is kind of confusing. A simple rewrite for example.com/press/something to press.example.com/something would be like the one below RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^press/(.*)$ http://sub.example.com/$1 [R=301,L] Believe you are expecting something different mentioning about old urls and new urls for SEO. Examples would illustrate better. Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1373168 Share on other sites More sharing options...
vexx Posted August 28, 2012 Author Share Posted August 28, 2012 yep, I appoligize: the homepage, so to speak, is www.site.com/news/ ... i want this press.site.com All the links from the "news" section are www.site.com/press/press-name.html ...i want this press.site.com/press-name.html Tnx alot! Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1373302 Share on other sites More sharing options...
handlegeek Posted August 29, 2012 Share Posted August 29, 2012 Guess this will work for you RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^news http://press.example.com/ [R=301,L] RewriteRule ^press/(.*)$ http://press.example.com/$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1373534 Share on other sites More sharing options...
vexx Posted August 30, 2012 Author Share Posted August 30, 2012 that will work for redirecting the old urls to the new ones, but I kinda need the rewrite rule for the subdomain Now I have this: RewriteBase / RewriteRule ^news/index([0-9-]+)\.html$ index.php?page=pressrelease_homepage&pn=$1 RewriteRule ^news/$ index.php?page=pressrelease_homepage RewriteRule ^press/([a-zA-Z0-9-]+)-([0-9-]+)\.html$ index.php?page=pressrelease_page&id=$2 and I need to rewrite the subdomain like this RewriteRule ^press.site.com/index([0-9-]+)\.html$ index.php?page=pressrelease_homepage&pn=$1 RewriteRule ^press.site.com/$ index.php?page=pressrelease_homepage RewriteRule ^press.site.com/([a-zA-Z0-9-]+)-([0-9-]+)\.html$ index.php?page=pressrelease_page&id=$2 Evidently, those rewrite rules don't work..so that's why I need some help Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1373802 Share on other sites More sharing options...
handlegeek Posted August 31, 2012 Share Posted August 31, 2012 Unless I am misunderstanding what you are expecting, you can target your sub domain like this correct? RewriteEngine On RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC] RewriteRule ^(/)?$ index.php?page=pressrelease_homepage [L] RewriteRule ^index([0-9-]+)\.html$ index.php?page=pressrelease_homepage&pn=$1 [L] RewriteRule ^([a-zA-Z0-9-]+)-([0-9-]+)\.html$ index.php?page=pressrelease_page&id=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/267339-rewrite-and-redirecting-to-subdomain/#findComment-1374183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.