【问题标题】:URL rewrite with .htaccess for wildcard domain使用 .htaccess 重写通配符域的 URL
【发布时间】:2017-05-09 00:35:19
【问题描述】:

我想用通配符重写网址:

https://any.example.com

收件人:

https://example.com/fixed/any

'any' 是任意字符串,'fixed' 是固定字符串。

谢谢。

【问题讨论】:

  • 感谢您告诉我们这个!
  • 你能显示你的通配符域的VirtualHost 配置吗?
  • 也许可以选择使用自定义路由?

标签: php .htaccess codeigniter mod-rewrite url-rewriting


【解决方案1】:

尝试在您的.htaccess 文件中添加一些这样的重写规则:

RewriteEngine on
RewriteBase /

# Make sure it's not an actual file or 
# directory, being accessed. If you wish.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

# Match the subdomain
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$

# Rewrite the request to the main domain:
# %1: The subdomain matched against HTTP_HOST in the previous RewriteCond.
# $1: The request URI.
RewriteRule ^(.*)$ https://example.com/fixed/%1/$1 [L,R,QSA]

如果这不是最后的重写规则,请随意删除 L 标志。有关这方面的更多信息,请参阅RewriteRule Flags

你可以test it online

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多