php - 将域名重写为 url

标签 php .htaccess mod-rewrite

我有主域,例如domain.com,我需要重写另一个到url,例如如果域不是domain.com并且域是http://www.yyaa.com/say将其重写为 http://domain.com/index.php?p=say

RewriteEngine on
RewriteBase /
RewriteRule (.*)  http://domain.tld/dashboard/$1   [P,QSA,L]

最佳答案

在执行重定向之前,使用 RewriteCond 检查所使用的域名是否不等于 domain.com:

RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*)  http://domain.com/index.php?p=$1   [L,R=301]

关于php - 将域名重写为 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9125841/

相关文章:

php - 文件版本控制以消除浏览器缓存问题

php - 缓存index.php页面的搜索引擎有siteController但在yii PHP中没有模型

.htaccess - 如何在htaccess中将新域重定向到旧域的子页面

mod-rewrite - 为 SEO 重写单页模组

PHP/SQL JOIN 2 个表并获得平均分

php - MySQL 将员工每天的工作时间与日期联系起来

.htaccess RewriteRule 在子目录中不起作用

.htaccess 多个域重定向到一次 https 没有 www

asp.net - Mod Rewrite MS Hosting 通过显示短 URL 隐藏长烦人的 URL?

regex - .htaccess 为每个子目录设置默认页面