Jump to content

htaccess redirect


ionutvmi

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/245806-htaccess-redirect/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/245806-htaccess-redirect/#findComment-1262766
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/245806-htaccess-redirect/#findComment-1263423
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.