喜欢的URL与查询字符串URL重定向到搜索引擎友好的目录 [英] Redirect urls with query string to seo-friendly directory like urls

查看:210
本文介绍了喜欢的URL与查询字符串URL重定向到搜索引擎友好的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题是问的多用户,我也经历了许多的问题去寻找解决办法,因为我无法理解htaccess文件中使用的code。所以,请您帮我解决这个问题。我只是想转换的链接,如:

I know this question is asked by many users, also I gone through many questions to find the solutions as I am unable to understand the code used in htaccess file. So please kindly help me to solve this issue. I just want to convert a link like:

www.abc.com/project.php?proj-cat=some+project+name

www.abc.com/project.php?proj-cat=some+project+name

到URL如:

www.abc.com/project/some+project+name

www.abc.com/project/some+project+name

或者喜欢的:

www.abc.com/project/some-project-name /

www.abc.com/project/some-project-name/

我用Google搜索,发现了一个网站,为您创建一个htaccess的规则,使用本网站我得到这样的:

I googled and found a website which creates a htaccess rule for you, using this site I got this:

RewriteEngine on
RewriteRule project/proj-cat/(.*)/ project.php?proj-cat=$1 [L]

但这并不重定向到上面的链接。 请帮我找到这个解决方案,并帮助我理解它是如何工作的。谢谢!

but this doesn't redirect to the links above. Please help me to find the solution for this and help me understand how it works. Thank You!

推荐答案

您可以在根目录的.htaccess使用code:

You can use this code in root .htaccess:

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+project\.php\?proj-cat=([^\s&]+) [NC]
RewriteRule ^ project/%1? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^project/([^/.]+)/?$ project.php?proj-cat=$1 [L,QSA,NC]

这篇关于喜欢的URL与查询字符串URL重定向到搜索引擎友好的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆