Forum Moderators: phranque
1. How to convert www.mydomain.com/folder/anyfile.php?user=xyz TO xyz.mydomain.com/anyfile.php?user=xyz
If I read you right, you're making the same error most do when taking their first stab at rewrite. You have it backwards. in your page, you have
<a href="/anyfile.php?user=xyz">XYZ</a>
Then you rewrite to xyz.mydomain.com/folder/anyfile.php?user=xyz
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^anyfile.php\?([a-z=]*)$ [xyz.mydomain.com...] [NC]
</ifModule>
Better yet,
<a href="/Users/xyz">XYZ</a>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Users\/([a-z]+)$ [xyz.mydomain.com...] [NC]
</ifModule>
Had to use https so the stupid widget here doesn't screw up the code! You wouldn't use https . . . .
So if someone requests just /Users, user= will be empty, and you can manage it accordingly (show full user list?)
[NC] makes it case insensitive.
I want the URL should appear with the USERNAME of Logged in user, So I am going to add the username to all the links as www.example.com/company/abc.php?user=username
So now what I need it the above URL should be http://username.example.com/company/abc.html
For this I will make all the links in the site as <a href='username.example.com/company/abc.html'>Link</a>
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond %1 !=www
RewriteRule ^company/([^./]+)\.html$ /company/$1.php?user=%1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /company/[^.]+\.php\?user=([^&\ ]+)\ HTTP/
RewriteRule ^company/([^.]+)\.php$ http://%1.example.com/comapany/$1.html? [R=301,L]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond %1 !=www
RewriteRule ^company/([^./]+)\.html$ /company/$1.php?user=%1 [L]
Options +FollowSymLinks
RewriteEngine on