简体   繁体   English

如何同时使用mod_rewrite和URL重定向

[英]How to use mod_rewrite and Url redirection at same time

I have a url like this 我有一个这样的网址

post_article.php?url=how-to-use-mod-rewrite

I am using mod_rewrite to make it 我正在使用mod_rewrite使它

post/how-to-use-mod-rewrite

Code I am using in .htaccess 我在.htaccess中使用的代码

RewriteEngine On
RewriteRule ^post/([^/]+)/?$ post_article.php?url=$1 [L]

Now both of this urls will give the same content, which is not good in SEO point of view. 现在,这两个网址将提供相同的内容,从SEO的角度来看这是不好的。 How I can redirect all those old urls to new url . 我如何将所有这些旧网址重定向到新网址

ie post_article.php?url=any-value to post/anyvalue 即post_article.php?url =要发布的任何值/任何值

如果您仅关注SEO,请使用规范的URL来帮助搜索引擎理解重复的内容。

RewriteEngine On
Redirect ^post_article.php?url=.*$ post/$1
RewriteRule ^post/([^/]+)/?$ post_article.php?url=$1 [L]

Try it. 试试吧。

只需创建一个函数以重写文章中的所有链接,搜索引擎将永远无法找到旧的url方案。

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

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