ionutvmi Posted August 27, 2011 Share Posted August 27, 2011 hello i'm working on a project and i'm stuck i need to make something like this from htaccess subname.domain.com to be redirected to page.php?a=subname also subname.domain.com/?act=do to be redirected to page.php?a=subname&act=do and i also need the url to stay unchanged after redirection can anybody help ? Quote Link to comment https://forums.phpfreaks.com/topic/245806-htaccess-redirect/ Share on other sites More sharing options...
cags Posted August 28, 2011 Share Posted August 28, 2011 You will need to ensure that you have wildcard sub-domains set on your DNS, and that they are set to go to the same VirtualHost, you will then simply need something like this... RewriteCond %{HTTP_HOST} (.*)\.domain\.com RewriteRule ^$ /page.php?a=%1 [QSA,L] The RewriteCond capture the subdomain, the RewriteRule matches empty strings (you may wish to amend that part) and rewrite it to the format you requested. The QSA will ensure that the QUERY_STRING from the original URL get's persisted. Quote Link to comment https://forums.phpfreaks.com/topic/245806-htaccess-redirect/#findComment-1262766 Share on other sites More sharing options...
ionutvmi Posted August 28, 2011 Author Share Posted August 28, 2011 thank you it works Quote Link to comment https://forums.phpfreaks.com/topic/245806-htaccess-redirect/#findComment-1262768 Share on other sites More sharing options...
ionutvmi Posted August 30, 2011 Author Share Posted August 30, 2011 hello again i've tried that code and it works but now i need subname.domain.com/somepage.php to be redirected to domain.php/apage.php?n=subname so i added a line in htaccess like RewriteRule ^somepage\.php$ apage.php?n=%1 [QSA,L] and it works but the problem is that when i try to access subname.domain.com it sends me on an endless loop what can i do ? Quote Link to comment https://forums.phpfreaks.com/topic/245806-htaccess-redirect/#findComment-1263423 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.