php - 使用动态主机名重写 url

标签 php .htaccess url-rewriting

我需要使用如下规则重写 url

RewriteRule ^files/([a-z0-9-\.]+)$ files/domain.com/$1

domain.com 是当前主机名。它是动态的(请不要问为什么)。所以我不能这样做。无论如何,我如何获取当前主机名并将其写成这样:

RewriteRule ^files/([a-z0-9-\.]+)$ files/{{ current host name with out www. }}/$1

最佳答案

%{HTTP_HOST} 将为您提供请求的主机名。

我现在无法测试它是否可以在 RewriteRule 中使用,但我认为可以。

关于php - 使用动态主机名重写 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3659354/

相关文章:

php解析汇率提要XML

PHP 变量未填充到表单上的 HTML 日期时间本地字段中

php - .htaccess 拒绝访问特定文件?超过一个

php - 如何制作默认页面 home.php 而不是 index.html 和 index.php

.htaccess mod_rewrite 域之间的重定向

.htaccess - 配置文件系统的重写规则

根目录下的 Tomcat SES 友好 URL (Lucee/Railo)

php - 缩短特定字符串的函数

IIS 网址重写 : how to ignore minified javascript and css

php - 如何根据访问者路径获取mySQL的行?