0

i am trying to implement dynamic

RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]

Now this .htaccess converts

http://mydomain.com/live/agent/index.php?agent_user_name=username to http://username.mydomain.com

and

http://mydomain.com/live/agent/forum.php?agent_user_name=username to http://username.mydomain.com/form/

However, there are other pages as well which i want to redirect to subdomain like

http://mydomain.com/live/agent/view_blog.php?agent_user_name=username&blog_id=19 this page should be read via subdomain something like http://username.mydomain.com/view_blog/19 etc and also

http://mydomain.com/live/agent/page.php?agent_user_name=username&content_id=19 this page should be accessed by http://username.mydomain.com/content/19 etc

Thanks

2 Answers 2

1

This should work:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^content/([0-9]+)/?$ /live/agent/page.php?agent_user_name=%1&blog_id=$1 [L,QSA]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^([^/]+)/([0-9]+)/?$ /live/agent/$1.php?agent_user_name=%1&blog_id=$2 [L,QSA]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]
3
  • anubhava, you didn't mention page_id variable in .htaccess rule... ??? there can be more extra variables as well like for blog section we may have blog.php?agent_user_name=username&page=1&search=property ????
    – imran
    Commented Apr 1, 2014 at 6:14
  • There was no page_id in your examples. For more variables you can follow same pattern as I suggested and expand rules for extra variables.
    – anubhava
    Commented Apr 1, 2014 at 7:20
  • RewriteRule ^([^/]+)/([0-9]+)/?$ /live/agent/$1.php?agent_user_name=%1&blog_id=$2 [L,QSA] for this rule, can u please advise if i change blog_id with page_id, how can i make it to access page.php instead of view_blog.php ???
    – imran
    Commented Apr 1, 2014 at 8:42
0

Add the following below your current rules should achieve what you want.

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/view_blog.php\?agent_user_name=(.*)&blog_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/view_blog/%3? [R,L]

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/page.php\?agent_user_name=(.*)&content_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/content/%3? [R,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.