简体   繁体   English

用 .htaccess 为 php 脚本重写域 url

[英]Rewrite domain url for php script with .htaccess

php or js script works correctly only on domain1.com php 或 js 脚本仅在 domain1.com 上正常工作

Can I fool them with .htaccess to think I use domain1.com while actually having domain2.com in url?我可以用 .htaccess 欺骗他们以为我使用 domain1.com 而实际上在 url 中有 domain2.com 吗? That is having $_SERVER['SERVER_NAME'];那就是有$_SERVER['SERVER_NAME']; return domain2.com返回域 2.com

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?domain2.com$ [NC]
RewriteRule ^ http://domain1.com%{REQUEST_URI}

These instructions aren't quite working.这些说明不太管用。

There is an alternative that is not related to.htaccess but you can create an index.php in your root of domain 2 and redirect it to domain1 like this:有一个与 .htaccess 无关的替代方案,但您可以在域 2 的根目录中创建一个 index.php 并将其重定向到域 1,如下所示:

<?php
$uri = $_SERVER['REQUEST_URI'];
header('Location: http://domain1.com'.$uri);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM