2

I'm not good at .htaccess & I want to change query parameter of url & redirect to other URL

Here is my condition:

-If URL has parameter called share_id=xxx than it changes to other paremeter & redirect

Ex:

My current url: http://www.wpstructure.com/870/top-10-best-movies-a-must-watch/?share_id=883

& I want to redirect to: http://www.wpstructure.com/870/top-10-best-movies-a-must-watch/#share_id-883

Replace ? with # and = with - only if URL has query paremeter share_id

1 Answer 1

2

You can use this rule in your htaccess :

RewriteEngine On
RewriteCond %{QUERY_STRING} ^share_id=([^&]+) [NC] 
RewriteRule ^ /870/top-10-best-movies-a-must-watch/#share_id-%1? [NC,R,L]

Or try this

RewriteEngine On
RewriteCond %{THE_REQUEST} /([^/]+)/\?share_id=([^&\s]+) [NC] 
RewriteRule ^ /%1/#share_id-%2? [NC,R,L]
Sign up to request clarification or add additional context in comments.

5 Comments

URL wpstructure.com/870/top-10-best-movies-a-must-watch/… is dynamic so how can i get /870/top-10-best-movies-a-must-watch/
Not working..it redirect to wpstructure.com/top-10-best-movies-a-must-watch/… and # is not coming in url i thinks it's encoded
ok..just tell me how can i get /870/top-10-best-movies-a-must-watch/ this part from url
You can use the second solution I provided, it captures dynmic url paths and then uses it as %1.
Ok.......Thanks it's working fine...just need to change condition parameter NC to NE then it's not encoding #

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.