0

在使用通配符子域时,我在链接到页面时遇到了麻烦,希望能在找出解决方案方面提供一些帮助。

我希望用户拥有自己的子域来查看自己的网站内容,因此如果用户输入“user1.domain.com”,服务器将有一个重写规则,将请求定向到根目录中的 index.php 页面。此 index.php 页面将用于所有子域,并将根据查询字符串中传递的子域从数据库中提供内容。

这部分工作得很好,它提供了 index.php 中的内容。当 index.php 页面加载时,它包含一个菜单(主页 | 租赁 | 联系我们)。当我单击菜单链接转到另一个页面时,问题就来了。URL 地址发生变化,但页面内容不变。

下面是一个示例:如果我单击“RENTALS”,我希望用户转到rentals.php 页面并显示“user1”子域可用的租金......但这是正在发生的事情:

链接场景一:

<a href="http://user1.domain.com/rentals.php">RENTALS</a>   --> URL address bar changes to "user1.domain.com/rentals.php" but the page doesn't change, it still stays on the index.php content

链接场景2:

 < a href="rentals.php" >RENTALS< /a >   --> URL address bar changes to "user1.domain.com/rentals.php" but the page doesn't change, it still stays on the index.php content

链接场景 3(如果我对域进行硬编码并省略通配符子域,则链接有效):

<a href="http://www.domain/public_site/rentals.php">RENTALS</a>   --> URL address bar changes to "http://www.domain.com/public_site/rentals.php" AND IT WORKS, the rentals.php page loads and serves up the content.

方案 3 的问题是我希望 url 读取:“user1.domain.com/rentals.php”

我想知道这是否可以在重写条件下设置,但我无法弄清楚。

如果有人可以提供帮助,我将不胜感激!

这是我的目录结构:

ROOT
  |
  PUBLIC_SITE
     |
     index.php
     rentals.php
     contactus.php

这是apache重写规则(第一条规则有效。我添加的第二条规则希望解决我的问题,但它没有解决问题):

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On

   ####Rewrite subdomain request to public_site/index.php
   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
   RewriteRule ^(.*)$  /public_site/index.php?subdomain=%2 [L]

   #### Rewrite rule for rentals.php page
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com/rentals.php [NC]
   RewriteRule ^(.*)$  /public_site/rentals.php?s=%2 [L]

</IfModule>
4

1 回答 1

0

进入重写后我自己想通了...

只需将此代码放在“主域”规则之前:

#### Rewrite rule for rentals.php page
   RewriteCond %{REQUEST_URI} ^/rentals.php?$ [NC]
   RewriteRule ^(.*)$  /public_site/rentals.php [L]
于 2011-12-09T21:24:01.213 回答