apache - htaccess mod_rewrite 主机名

标签 apache .htaccess mod-rewrite redirect debian

如果不匹配,我如何将域 url 重写为特定域名..

假设我希望它只匹配 example.com 并且访问者来自服务器 ip (http://127.0.0.1/something/else) 或来自另一个域 (http://domain.com/something/else)

我怎样才能重写域名并保留所有其他参数,只是域名到 example.com(结果应该是:http://example.com/somthing/else)

最佳答案

尝试将这些规则添加到文档根目录中的 htaccess 文件中:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R]

关于apache - htaccess mod_rewrite 主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13021893/

相关文章:

apache 虚拟主机和 "Dynamic"域

php - mod_rewrite 不工作 xampp(附图片)

wordpress - 如果请求方法是 post 则 .htaccess 重定向

apache - 使用 htaccess 重定向到同一域

php - 打开时出现 WAMP 服务器 2 错误

apache - 如何更改 uwamp apache 版本

linux - 包括不工作

php - 使用 htaccess 和 php 的 mp3 带宽限制

javascript - URL重写: Show all files of certain directories at root of site

java - 导出的 .jar 上的 Apache POI 未在其他计算机上运行