0

I have a url like

http://www.mywebsite.com/shop-single-full.php?img=35

I want to rewrite and redirect this url like

http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html

where text is the product name. I also want when someone want to access

http://www.mywebsite.com/shop-single-full.php?img=35 

it will automatically redirect it to

http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html

Whatever I have tried is

RewriteRule ^shop-single-full/?$ ([A-Za-z0-9_\-]+)\-([0-9]+).html?%1 [R,L]
RewriteRule ^([A-Za-z0-9_\-]+)\-([0-9]+).html?$ /shop-single-full.php?img=$2&name=$1

but there is some problem in redirection.Thanks

123
  • 10,778
  • 2
  • 22
  • 45
Abhishek Mishra
  • 340
  • 4
  • 14
  • Will different img ID's have different url names? Like `?img=10 => /some_product-10.html`, `?img=20 => /another_product-20.html`? In that case, you need to do it in your code, not with rewrite, since you need to fetch the name by it's ID somehow. Unless you want to define them all in your rewrite rules? – M. Eriksson Sep 14 '16 at 12:51
  • Btw.. you say _"I also want..."_ and then you explain the exact same thing again? – M. Eriksson Sep 14 '16 at 12:53
  • @MagnusEriksson that's different from each other.If some try to open ugly url it should not open and redirect it to pretty url.(I am talking in that case where url rewriting has been done but not redirecting) – Abhishek Mishra Sep 14 '16 at 13:00
  • Please update and phrase your question(s) more clearly. You actually say that you want to redirect in both cases. First: (rewrite and redirect) and second: (automatically redirect to). I can't see any real difference. Rewrite can't change the URL without redirecting it... Look at the marked answer here for a more indepth explanation: http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained – M. Eriksson Sep 14 '16 at 13:05
  • at this time i just want to redirect my urls like /shop-single-full.php?img=10 & name=some-product => /some-product-10.html because i have done url rewriting.Please update a solution for doing this in .htaccess. – Abhishek Mishra Sep 14 '16 at 16:29

1 Answers1

0

Use header() in shop-single-full.php

header("Location: http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html");

Read more about header() here

jophab
  • 5,356
  • 14
  • 41
  • 60
  • i just want to block /shop-single-full.php in htaccess with /Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html what can i do for that?? – Abhishek Mishra Sep 14 '16 at 16:24