0

how can i convert my users profiles URL to subDomain with htaccess

I tried used this code in htaccess but it's not work

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(iemg\.net)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Like : http://iemg.net/usersprofile.php?username=mohamed to http://mohamed.iemg.net

GoldenFingers
  • 119
  • 1
  • 2
  • 10

1 Answers1

0

First, you must capture the user part of the domain, and then use this in the substitution

RewriteCond %{HTTP_HOST} ^(.*)\.iemg\.net$ [NC]
RewriteRule ^ http://iemg.net/usersprofile.php?username=%1 [R,L]

When everything works as it should, you may replace R with R=301. Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • i was added your code into my htaccess file and when i enter to this path [link](http://username11.iemg.net/) found this error `"This site can’t be reached username11.iemg.net’s server DNS address could not be found. "` – GoldenFingers Feb 15 '17 at 10:35
  • This has nothing to do with the rewrite rule. You must setup your DNS addresses, of course, before this can work. You need to setup your Apache's virtual host config to serve these domains also. A wildcard DNS entry should work as well. – Olaf Dietsche Feb 15 '17 at 11:59