Question

I am trying to create custom domain names using .htacess

Here is what i am doing

http://username.mydomain.com is accessing http://mydomain.com/live/agent/index.php?agent_user_name=username (working fine)

here is .htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]

RewriteCond %1 !^www$ [NC]

RewriteRule ^$ /live/agent/index.php?agent_user_name=%1 [L]

But now I want to handle other pages as well

http://username.mydomain.com/blog should access http://mydomain.com/live/agent/blog.php?agent_user_name=username

Please help how to handle this as well in .htaccess

Was it helpful?

Solution

You can have this additional rule:

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top