用htaccess重写域名/URL [英] Rewrite domain name/url with htaccess
本文介绍了用htaccess重写域名/URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要重写以下网址:
mydomain.com/dashboard/index.php?user=john-dow
到
john-dow.mydomain.com/dashboard/index.php
因此,我想获取查询字符串值,并将其放在域的开头,后跟一个点.目标是创建自定义的用户url,因此对用户而言看起来非常友好.但是实际上,我不知道该怎么办. .htaccess有可能吗?如果是,怎么办?
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?
推荐答案
在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]
这篇关于用htaccess重写域名/URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文