.htaccess: mod-rewrite; subdomain

后端 未结 3 588
梦如初夏
梦如初夏 2020-12-15 15:05

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

相关标签:
3条回答
  • 2020-12-15 15:25

    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
    
    0 讨论(0)
  • 2020-12-15 15:33

    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

    0 讨论(0)
  • 2020-12-15 15:37

    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/
    
    0 讨论(0)
提交回复
热议问题