问题
I need to rewrite the following url:
mydomain.com/dashboard/index.php?user=john-dow
to
john-dow.mydomain.com/dashboard/index.php
So I want to take the query string value and place it at the beginning of my domain followed by a dot. The goal is to create a customized user url, so it looks very friendly to users. But actually, I don't know how can I do that. Is it possible by .htaccess? If yes, how?
回答1:
Use in your dashboard/.htaccess
:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(.+)\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^user=(.+)$
RewriteRule ^index\.php$ http://%1.mydomain.com/dashboard/index.php? [R,L]
来源:https://stackoverflow.com/questions/33187889/rewrite-domain-name-url-with-htaccess