-1

I am new at this. How can I rewrite this in .htaccess correctly?

My visitor access: http://www.example.com/old/xxx/?id=1

But actually source is from: http://www.example.com/new/(same name with xxx)/1.html

halfer
  • 19,824
  • 17
  • 99
  • 186
coco
  • 1

1 Answers1

0

You can try this

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteCond %{REQUEST_URI} ^/old/xxx/?id=%1\.html$
RewriteRule ^(.*)$ http://www.siteurl.org/new/xxx/?id=%1\.html [L,R=301]
parrycima
  • 905
  • 8
  • 19
  • Thank you so much parrycima. How can I deal with xxx (It should be the same name with old one and changing from time to time) – coco Jul 27 '19 at 12:01
  • check out this one. It's similer to your question https://stackoverflow.com/questions/44567637/htaccess-redirect-variable-to-friendly-link-many-redirects – parrycima Jul 29 '19 at 09:04