how to Rewrite two parameters URL to SEO friendly URL and Redirect to SEO friendly url

狂风中的少年 提交于 2019-12-24 18:25:04

问题


This is my page url example.com/platform/bidProject.php?pID=JCVGK&name=Proof%20Reading%20Blogs

These rules helped me to Rewrite this as example.com/platform/project-bids/JCVGK/Proof-Reading-Blogs/

RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]
RewriteCond %{THE_REQUEST} \s/platform/bidProject.php?pID=$1&name=$2 
RewriteRule ^platform/bidProject.php?pID=$1&name=$2 /platform/project-bids/(.*)/(.*)/ [NC,R=301,L]

but the issue is if I visit to the page example.com/platform/bidProject.php?pID=JCVGK&name=Proof%20Reading%20Blogs the url stays same. I want this to be redirected to example.com/platform/project-bids/JCVGK/Proof-Reading-Blogs/

So I tired this:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]

RewriteRule ^([^/]+)/([^/]+)/?$ /platform/bidProject.php?pID=$1&v=$2 [L,QSA]

Seems I am doing something wrong with this because it makes no any affect on this.

I found a solution to redirect using JavaScript but I like to have .htaccess solution because JavaScript can be disable and can be seen in the source code. The basic intention for doing this fails here.

How can I achieve this using .htaccess

My htaccess path is example.com/.htacsess


回答1:


You can use these Rules

RewriteEngine on
#redirects /platform/bidProject.php. php?pid=val1&name=val2 to /platform/project-bids/val1/val2/
#redirects the old url to the new one
RewriteCond %{THE_REQUEST} \s/platform/bidProject.php\?pID=([^&]+)&name=([^&\s]+) [NC]
RewriteRule ^ /platform/project-bids/%1/%2/? [NC,R,L]
# rewrites or internally maps the new url to the old one
RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]

Or

RewriteEngine on
RewriteCond %{ENV_REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^pid=([^&]+)&name=([^&]+)$ [NC]

RewriteRule ^platform/bidProject.php$ /platform/project-bids/%1/%2/? [NC,R,L]
RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]

Change R to R=301 (permanent redirect) when you are sure the rule is working ok.



来源:https://stackoverflow.com/questions/48394524/how-to-rewrite-two-parameters-url-to-seo-friendly-url-and-redirect-to-seo-friend

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