apache - 使用 HTAaccess 更改网站链接
问题描述
是否可以使用 .htaccess 重写子域?
例子:
http://fashion.example.com
显示的内容
http://example.com/index.php?name=fashion
<IfModule mod_rewrite.c>
# Turn on the rewrite engine
RewriteEngine on
RewriteRule %{REQUEST_URI} ^(.*).example.com/$ index.php?name=$1
</IfModule>
解决方案
假设您的子域指向与主域相同的目录,您可以使用如下内容:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^((?!www).+)\.example.com$
RewriteRule ^(.+)/?$ /index.php?name=%1 [L]
推荐阅读
- python - 不清楚 If 语句的功能
- javascript - typescript/javascript:如何从特定目录导入所有 json
- python - 函数调用 Python 中缺少必需的潜在参数
- python - 如何在 Python 控制台中运行带有选项的 .py 文件?
- php - 当laravel中的key_names不同时如何检查两个数组的相等性
- r - R中轨迹数据的NetCDF显示
- jsreport - 是否可以使用 jsreport 和 chrome pdf 配方创建带有下拉字段的 pdf?
- python - 文本到语音(pyttsx3)模块不工作
- dart - 在项目文件夹之外运行 dart 脚本
- c# - 所有语言/编码的字符计数?