2
votes

I have a sub-domain for my mobile app which is like http://m.traffic.domain.com now I want that my users can access their page by visiting http://m.traffic.domain.com/username which will internally point to http://m.traffic.domain.com/index.php?username=$1 for this I have following .htaccess rewrite code but its not working as expected rather its redirecting all pages to http://m.traffic.domain.com/index.php?username=$1 this page

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
AddHandler application/x-httpd-php .aspx
RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\.traffic\.domain\.com$  [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^(.+)$ mobile/index.php?username=%1 [L]
<Files 403.shtml>
order allow,deny
allow from all
</Files>

The subdomain http://m.traffic.domain.com points to a directory called mobile which can be accessed http://traffic.domain.com/mobile

1

1 Answers

2
votes

Try this code instead:

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
AddHandler application/x-httpd-php .aspx

RewriteEngine On

RewriteCond %{HTTP_HOST} ^m\.traffic\.domain\.com$  [NC]
RewriteRule ^([^.]+)/?$ /index.php?username=$1 [L,QSA]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

Matched groups from RewriteRule are $1, $2 instead of %1, %2 and you don't need /mobile since your request is for m.traffic.domain.com not traffic.domain.com