简体   繁体   English

使用htaccess文件的URL重定向,URL友好到URL友好重定向

[英]URL redirect using htaccess file, url friendly to url friendly redirect

I have a url that I want to redirect 我有一个要重定向的网址

OLD URL -> https://www.my-webiste.com/products/title-of-product 旧网址-> https://www.my-webiste.com/products/title-of-product

NEW URL -> https://www.my-website.com/title-of-product 新网址-> https://www.my-website.com/title-of-product

On google we have everywhere old url and we changed the site with new layout and CMS so we redirected our domains ( old-website.com -> new-website.com this works well ) but I am not sure how I can able to pass this parameter to new store, any help? 在google上,我们到处都有旧的url,我们用新的布局和CMS更改了网站,因此我们重定向了域名(old-website.com-> new-website.com,这很好用),但是我不确定如何能够通过这个参数到新店,有什么帮助吗?

If that is not possible,then can we load content of https://www.new-website.com/title-of-product on https://www.new-website.com/products/title-of-product url ? 如果这不可能,那么我们可以在https://www.new-website.com/products/title-of-product网址上加载https://www.new-website.com/title-of-product的内容?

So when user come to my site with old url, in backend system ( htaccess ) will manage to skip "products" keyword internally and show appropriate page. 因此,当用户使用旧的url进入我的网站时,后端系统(htaccess)将设法在内部跳过“ products”关键字并显示适当的页面。

RewriteRule ^/?products/([^/d]+)/?$ /$1 [L,QSA] RewriteRule ^ /?products /([[^ / d] +)/?$ / $ 1 [L,QSA]

RewriteRule ^products/?$ $1/new-page$2 [R=301,L] RewriteRule ^ products /?$ $ 1 / new-page $ 2 [R = 301,L]

RewriteRule ^products/(\\d+)?$ /$1 [L] RewriteRule ^产品/(\\ d +)?$ / $ 1 [L]

RewriteRule ^([^?]*) index.php? RewriteRule ^([[^?] *)index.php? route =$1 [L,QSA] 路线 = $ 1 [L,QSA]

RewriteRule ^(. )/products/(. )$ $1/$2 [R=301,L] RewriteRule ^(。 )/ products /(.)$ $ 1 / $ 2 [R = 301,L]

RewriteRule ^products/(.*)$ /$1 [R=301,L] RewriteRule ^产品/(.*)$ / $ 1 [R = 301,L]

RewriteRule ^products/(.*)$ /%1 [L,R=301] RewriteRule ^产品/(.*)$ /%1 [L,R = 301]

I tried all of these but I am getting 404 with all of above. 我尝试了所有这些,但以上所有都得到了404。 Rewrite Engine is on as when https://www.new-website.com/title-of-product I open this url it works fine. 当我打开此URL时,重写引擎打开,因为https://www.new-website.com/title-of-product正常运行。

In short conclusion is: 简短的结论是:

i just have to get rid of "products" from the urls and send that parameters. 我只需要从网址中删除“产品”并发送该参数即可。

if someone open https://www.my-webiste.com/products/title-of-product then they must be go to https://www.my-webiste.com/title-of-product ( see without products ) That's it. 如果有人打开https://www.my-webiste.com/products/title-of-product,那么他们必须转到https://www.my-webiste.com/title-of-product (请参阅无产品)而已。

Thanks in advance. 提前致谢。

Firstly, please make sure you have rewrite module turned on, can be checked with phpinfo(); 首先,请确保您已打开重写模块,可以使用phpinfo()进行检查; function 功能

if it is on, then this code placed in .htaccess file in the main public folder of your project should work: 如果已打开,则放在项目主公用文件夹中的.htaccess文件中的此代码应该可以工作:

RewriteEngine On
RewriteRule ^products/(.*)$ https://www.new-website.com/$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM