Forum Moderators: phranque
I am writing a rewrite rule for redirecting the sub domain
Example : abc.example.com to www.example.com/user/abc
My .htaccess file is
RewriteCond %{HTTP_HOST} ^(([a-zA-Z0-9_-]+)+\.)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI}/user/%1 [R=301,L]
The problem is that when I use this rule the URL :
abc.example.com will be redirected to example.com/user/abc.
At the end a dot(.) is comming. is any solution for this...
Also, since you're using [NC], there's no need to include both A-Z and a-z in the pattern. Remove one or the other to improve performance. And do not end-anchor the hostname, or it will fail if a FQDN is requested or port number is appended. There also appears to be an extra "+" in there.
RewriteCond %{HTTP_HOST} ^(([a-z0-9_-]+)\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI}/user[b]/%2[/b] [R=301,L]
Jim