重定向到一个页面,无需更改URL [英] redirect to a page without changing the url
问题描述
我已经安装了一个词preSS网站 mywebsite.com/fr / 我想在页面的 mywebsite.com/fr/testpage / 重定向到 mywebsite.com/fr/pagewithweirdurl / ,但仍然显示在URL中的 mywebsite.com/ FR / testpage / 我发现重定向精细的插件,但它总是变化的URL。 我发现很多htaccess的codeS在这里做我想做的,但他们这样做对整个网站的,我只需要这些特定的网页做我想要的。剩下的就是好的。
i have a wordpress site installed on mywebsite.com/fr/ i want the page mywebsite.com/fr/testpage/ to redirect to mywebsite.com/fr/pagewithweirdurl/ but still showing in the url mywebsite.com/fr/testpage/ i found plugins that redirect fine, but it always changes the url. i found many htaccess codes in here that do what i want, but they do it for the entire website, i just need these specific pages to do what i want . the rest is fine.
因此,如果有人可以帮助我一个htaccess code和告诉我如何改变在code中的网址的网页,我想我会很AP preciate它。 如果你知道一个插件,它重定向,同时保持网址,而不是改变其即时通讯有兴趣了。
so if someone could help me with an htaccess code and show me how to change the urls in the code for the pages i want i would really appreciate it. if you know a plugin that does the redirection whilst keeping the url and not changing it im interested too.
推荐答案
添加到您的的.htaccess
在Web根 /
目录
Add this to your .htaccess
in your web root /
directory
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^fr/testpage/?$ /fr/pagewithweirdurl/ [NC,L]
这里的关键是不要使用 [R]
标志重写规则,使外部重定向和改变浏览器的地址栏中的URL。这是假设 / FR / testpage /
物理上不存在。如果你想重定向一个现有的文件/目录中删除两个的RewriteCond
itions。
The key here is not use the [R]
flag for the rewrite rule which causes an external redirection and changes the URL in the browser's address bar. This assumes that /fr/testpage/
doesn't exist physically. If you're trying to redirect an existing file/directory remove the two RewriteCond
itions.
这篇关于重定向到一个页面,无需更改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!