【问题标题】:.htaccess: mod-rewrite; subdomain.htaccess:模组重写;子域
【发布时间】:2012-01-19 09:12:26
【问题描述】:

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

我需要链接:

  • user.mywebsite.com 到>> mywebsite.com/users/user
  • user2.mywebsite.com/contact 到>> mywebsite.com/users/user2/contact

某些链接可能没有链接,例如:

  • www.mywebsite.com 可能无法链接到 mywebsite.com/users/www

这可能与htaccess 有关吗? 如果是,谁能给我解释一下?

【问题讨论】:

  • 如果我理解你的最后一个问题,我会解释它

标签: .htaccess mod-rewrite subdomain


【解决方案1】:

使用mod_rewrite,你可以试试:

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

中的文件

【讨论】:

  • 为什么它给我 500 错误?我正在使用 codeigniter 并且在我的 htaccess 中使用没有 index.php 的漂亮 url,你能帮帮我吗?提前致谢。
【解决方案2】:

将旧链接重定向到新链接。

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

【讨论】:

  • 对不起,这不是我要找的。需要一些东西才能让它始终适用于每个帐户
【解决方案3】:

你可以看看VirtualDocumentRoot

例如www.user.isp.com 的文档位于 /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/

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 2011-02-04
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多