.htaccess: mod-rewrite; subdomain

无人久伴 提交于 2019-11-29 00:45:19

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]

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

Redirecting your old links to new ones.

Redirect user.mywebsite.com mywebsite.com/users/user
Redirect user2.mywebsite.com/contact mywebsite.com/users/user2/contact

You can take a look at VirtualDocumentRoot

e.g. the documents for www.user.isp.com are found in /home/user/.

# include part of the server name in the filenames
VirtualDocumentRoot /www/hosts/%2/docs

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