所以,一开始就更加形象化:
这是当前的链接结构:
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/