AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 393777
Accepted
tester
tester
Asked: 2012-05-30 15:44:12 +0800 CST2012-05-30 15:44:12 +0800 CST 2012-05-30 15:44:12 +0800 CST

使用查询字符串路由子域

  • 772
RewriteEngine on
Options -Indexes
DirectoryIndex index.php
RewriteBase /

RewriteRule ^user/([a-zA-Z]+)/([a-zA-Z]+)(/)?$ index.php?controller=main&function=$1&arguments=$2 [NC,L]

我可以mysite.com/one/two 去main->one(two)

我想以相同的方式路由子域请求。

我将如何设置这样的规则api.mysite.com来点击以下内容?

controller=api&function=$1&arguments=$2 [NC,L]

(允许我去 api.mysite.com/one/two 来点击 api->one(two))

routing subdomain .htaccess
  • 2 2 个回答
  • 395 Views

2 个回答

  • Voted
  1. Best Answer
    Tom
    2012-05-30T16:07:23+08:002012-05-30T16:07:23+08:00

    会是这样的

    RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com
    RewriteRule ^user/([a-zA-Z]+)/([a-zA-Z]+)(/)?$  \
      index.php?controller=%1&function=$1&arguments=$2 [NC,L]
    

    mod_rewrite 允许使用 %N,其中 N 为 1..9,以匹配来自先前的括号中的模式RewriteCond,因此%1用于替换api来自 rewriteCond 的域前缀

    • 3
  2. tester
    2012-05-31T10:00:01+08:002012-05-31T10:00:01+08:00

    我确实最终发现创建一个新的虚拟主机并将其指向一个新的、特定于 api 的 htaccess 文件更容易:

    ServerName api.mysite.com
    DocumentRoot /var/www/host/mysite.com/html
    AccessFileName .api.htaccess # <-- this did the trick
    
    • 0

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • 将路由永久添加到 Solaris 10

  • Quagga 套件中的 ./configure --disable-zebra 代表什么?

  • 使用特定接口进行出站连接(Ubuntu 9.04)

  • Linux TC/策略路由工具

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve