redirect to a page without changing the url

白昼怎懂夜的黑 提交于 2019-12-24 07:14:41

问题


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.

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.


回答1:


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]

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 RewriteConditions.



来源:https://stackoverflow.com/questions/19199004/redirect-to-a-page-without-changing-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!