的.htaccess:MOD重写;子域 [英] .htaccess: mod-rewrite; subdomain
本文介绍了的.htaccess:MOD重写;子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个新网站芽我想创建一个好看的网址为我的用户。我不知道的htaccess
任何事情,找不到我对谷歌的解决方案。
I am working on a new website bud I want to create a nice looking urls for my users. I don't know anything of htaccess
and could not find my solution on google.
我需要链接:
-
user.mywebsite.com
以>>mywebsite.com/users/user
-
user2.mywebsite.com/contact
以>>mywebsite.com/users/user2/contact
user.mywebsite.com
to>>mywebsite.com/users/user
user2.mywebsite.com/contact
to>>mywebsite.com/users/user2/contact
某些链接可能不会像链接:
Some links may not be linked like:
-
www.mywebsite.com
可能无法链接到mywebsite.com/users/www
www.mywebsite.com
may not link tomywebsite.com/users/www
这是possibe做的htaccess
?
如果是有人可以解释给我?
Is this possibe to do with htaccess
?
If yes can someone explain it to me?
推荐答案
使用mod_rewrite,你可以试试:
Using mod_rewrite, you can try:
RewriteEngine On
# the request URI doesn't already start with /users/
RewriteCond %{REQUEST_URI} !^/users/
# host doesn't start with www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# host starts with something else
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mywebsite\.com$ [NC]
# rewrite
RewriteRule ^(.*)$ /users/%1/$1 [L]
这将使它所以当有人进入 http://joe.mywebsite.com/some/page.html一>,他们将担任该文件的 /users/joe/some/page.html
This will make it so when someone enters http://joe.mywebsite.com/some/page.html they will be served the file in /users/joe/some/page.html
这篇关于的.htaccess:MOD重写;子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文