.htaccess:mod 重写;子域 [英] .htaccess: mod-rewrite; subdomain

查看:21
本文介绍了.htaccess:mod 重写;子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个新网站,我想为我的用户创建一个漂亮的网址.我对 htaccess 一无所知,也无法在 google 上找到我的解决方案.

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

某些链接可能无法链接,例如:

Some links may not be linked like:

  • www.mywebsite.com 不能链接到 mywebsite.com/users/www
  • www.mywebsite.com may not link to mywebsite.com/users/www

这可能与 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆