.htaccess:mod 重写;子域

编程入门 行业动态 更新时间:2024-10-28 03:32:36
本文介绍了.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 到>> mywebsite/users/user
  • user2.mywebsite/contact 到>> mywebsite/users/user2/contact

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

Some links may not be linked like:

  • www.mywebsite 不能链接到 mywebsite/users/www
  • www.mywebsite may not link to mywebsite/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$ [NC] # rewrite RewriteRule ^(.*)$ /users/%1/$1 [L]

当有人输入joe.mywebsite/some/page.html 他们将在 /users/joe/some/page.html

This will make it so when someone enters joe.mywebsite/some/page.html they will be served the file in /users/joe/some/page.html

更多推荐

.htaccess:mod 重写;子域

本文发布于:2023-10-31 17:30:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   htaccess   mod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!