Rewrite domain name/url with htaccess

谁说我不能喝 提交于 2019-12-13 07:16:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!