2011-12-11 62 views
0

我想保留域名/www.domain.com/whatever & www.domain.com/whatever对于我的主要应用程序站点,只是作为以下内容的前兆。.htaccess扩展子站点URL重写

对于我的用户,我的应用设置为他们的主页为username.domain.com。这很好,并显示他们的页面,但我遇到的问题是当我尝试处理username.domain.com/one,username.domain.com/one/two,username.domain.com/one/two/three

这里是目前我有什么,成功地将子域u.php

RewriteCond %{HTTP_HOST} ^(^.*)\.domain\.com$ 
    RewriteRule ^(.*)$ u.php 

我不需要,改变了(它的工作原理)。我现在需要的是:

  1. username.domain.com写入u.php(目前工作的伟大使用上述表达式)
  2. username.domain.com/one写入a.php只会请求=一个
  3. username.domain.com/one/two写入s.php?请求=一个&的ident =两个

编辑

下面是一些我之前调整了该工作的表达式应用程序跑掉用户子域,正好可以帮助:

RewriteRule ^([a-z\-]+)/?$ a.php?request=$1 [L] 
    RewriteRule ^/([a-z]+)/([a-z0-9\-]+)/?$ /s.php?request=$1&ident=$2 [L] 
    RewriteRule ^u/([a-z]+)/([a-z]+)/([a-z0-9\-]+)/?$ /s.php?user=$1&request=$2&ident=$3 [L] 

请记住

那我的问题目前是一切都会user.domain.com/one没有被改写。它仍然会u.php,当我想要它去s.php?request = $ 1

再次感谢您的帮助!

+0

您的子域名是否与www域名不同? –

+0

请发布“看起来不起作用”的代码。 – Gerben

+0

好 - 更新。请重新阅读它,因为我编辑了整个内容,希望更清楚。 – ingage

回答

0

你的第一行实际上是说:“不管是什么,发送到u.php”:

RewriteRule ^(.*)$ u.php 

一个问题,你在这里是在你已经把表达式的顺序。因为你的[L]标志... http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_l

RewriteRule ^([a-z\-]+)/?$ a.php?request=$1 [L] ## <- would match one/two/three and would stop the script from continuing because of the [L] flag. 
RewriteRule ^/([a-z]+)/([a-z0-9\-]+)/?$ /s.php?request=$1&ident=$2 [L] 
RewriteRule ^u/([a-z]+)/([a-z]+)/([a-z0-9\-]+)/?$ /s.php?user=$1&request=$2&ident=$3 [L] 

可能的解决方案

我都自己的意图连接成一个匹配表达式的,希望它为你...

RewriteRule ^([a-z\-]+)?/?([a-z\-]+)?/?([a-z\-]+)?/?$ u.php?first=$1&second=$2&third=$3 [L] 
RewriteRule ^(.*) u.php [L] 

此代码会向您发送一些空的参数......您应该在您的PHP代码中检查该参数。

如果你真的不想要,你总是可以分割你的代码...

RewriteRule ^([a-z\-]+)/([a-z\-]+)/([a-z\-]+)/?$ u.php?first=$1&second=$2&third=$3 [L] 
RewriteRule ^([a-z\-]+)/([a-z\-]+)/?$ u.php?first=$1&second=$2 [L] 
RewriteRule ^([a-z\-]+)/?$ u.php?first=$1 [L] 
RewriteRule ^(.*) u.php [L] 

注意表达的顺序。第三个表达式实际上会匹配一个/两个/三个。

我只是在这里使用[a-z-]。看看你自己的代码我想你知道如何添加对数字或大写字符的支持。