php - 子域重定向到完整 URL 并保留原始子域

标签 php wordpress .htaccess redirect

所以,一开始就更加形象化:

这是当前的链接结构:

http://example.com/video-slug/wordpress-title-of-the-video-slug

我有一个子域:

http://tv.example.com/

我想要实现的是,当有人点击时:

http://tv.example.com/wordpress-title-of-the-video-slug

它发现 tv.example.com 等于 example.com/video 并打开链接:

http://example.com/video/wordpress-title-of-the-video-slug,但将结构保留在地址栏中:

http://tv.example.com/wordpress-title-of-the-video-slug

最佳答案

更通用的解决方案,适用于您的问题。 它允许任何 http://subdomain.example.com/提供位于 http://example.com/subdomain/ 的内容同时保留原始 URL(带子域)。

P 选项(用于代理)可以实现此目的(将原始 URL 保留在地址栏中),并回答已接受答案评论中提出的问题(我无法回复评论..)

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/%1/$1 [L,P]

对于您的具体情况,它是

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^tv\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/video/$1 [L,P]

我现在面临的一个缺点是 PHP $_SERVER URI 设置为翻译后的 URL,而不是原始 URL。但这是另一个问题了:)

关于php - 子域重定向到完整 URL 并保留原始子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20997660/

相关文章:

php - 为什么 debug_backtrace() 有时不包含行号?

php - 通过PHP MongoDB Driver将数据从mongodb导入mysql应该怎么做?

php - 如何在第一次登录时随机获取记录?

.htaccess - 男孩的 htaccess 301 重定向

php - 子目录中的 Wordpress 克隆

php - $ 符号的 parse_ini_file 问题

javascript - 如何在单个产品页面 woocommerce 上显示高级自定义字段 Google map

mysql - 具有多个表和连接的 SQL 查询

mysql - 内部 JOIN 缺少行

php - zend 框架重定向问题 : Invalid controller specified