redirect to a page without changing the url

2019-08-08 19:55发布

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条回答
做自己的国王
2楼-- · 2019-08-08 20:21

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.

查看更多
登录 后发表回答