![](/img/trans.png)
[英]Redirecting “url a” to “url b” without changing “url a” in the browser
[英].htacess route url1 to url2 without changing the browser url
现在在用wordpress实现结果时遇到问题,想使用htacess做到这一点,想制作url
http://example.com/blog-preview/$any
通过http://example.com/blog/$any
访问
而不更改浏览器网址,即http://example.com/blog/$any
我不会使用htaccess文件执行此操作。 原因是htaccess文件只能重定向内容,但是-如果无法将内容从一页移动到另一页,这听起来就是您所追求的。
我将通过创建一个函数并将其放入functions.php
,然后使用file_get_contents来从需要显示的页面中获取内容来进行此操作。
function custom20190126_preview_function() {
$request_uri = $_SERVER['REQUEST_URI'];
$target_uri = '/blog/';
if( substr( $request_uri, 0, strlen( $target_uri ) === $target_uri ){
echo file_get_contents( 'https://example.com/blog-preview/foobar' );
die();
}
}
add_action( 'template_redirect', 'custom20190126_preview_function' );
如果要从WordPress的页面模板中执行此操作,则可以创建一个函数,并从页面模板中调用它(例如single.php
或archive.php
)。 像这样:
在archive.php中
<?php
echo file_get_contents( 'https://example.com/blog-preview/foobar' );
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.