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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.