如何将用户子域帐户重定向到子文件夹

时间:2018-02-24 14:15:37

标签: php .htaccess

请,我正在开展一个项目,我需要以字符串形式捕获网站的子域并查询用户数据库,然后在另一页中显示结果,而不更改URL。

例如: 如果用户访问 https://kelly.domain.com.xyz ,则会将子域名“Kelly”转换为名为 id 的字符串,搜索结果和在内部返回“userpage.php?id = kelly”中的查询,而不更改网址https://kelly.domain.com.xyz

这意味着userpage.php是用户子域的隐藏页面。

我的问题是,如何重写.htaccess以获取子域名并将其发送到userpage.php

以下是我到目前为止所尝试的内容,但它似乎不起作用:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com\.xyz
RewriteRule ^(.*)$ https://domain.com.xyz/subdomains/$1 [L,NC,QSA]
RewriteRule    ^subdomains/([A-Za-z0-9-]+)?$    subdomains/userpage.php?id=$1    [NC,L]    

如果我的代码很糟糕,请道歉,但我对.htaccess

不太满意

1 个答案:

答案 0 :(得分:0)

而不是htaccess使用PHP。对于PHP尝试下面的代码获取子域。

`<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="16dp">

    <android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.constraint.Guideline
            android:id="@+id/vertical_guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.6" />

        <TextView
            android:id="@+id/date_tv"
            android:layout_width="wrap_content"
            android:layout_height="16dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="2 hours ago" />

        <TextView
            android:id="@+id/source_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:textStyle="bold"
            app:layout_constraintLeft_toRightOf="@id/date_tv"
            app:layout_constraintTop_toTopOf="@id/date_tv"
            tools:text="BBC News" />

        <TextView
            android:id="@+id/headline_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="32dp"
            android:maxLines="2"
            android:textStyle="bold"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/date_tv"
            app:layout_constraintRight_toLeftOf="@id/vertical_guideline"
            tools:text="Apple admits slowing down older iphones" />

    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>`

而不是url参数,您将获得直接值。