0

My question is similar to, but not a duplicate of, .htaccess RewriteRule change underscore to dash

I'd like to re-write urls of this style:

http://example.com/?any_var=any_val

to this style:

http://example.com/any-var-any-val

The actual value of the QS does not need to be preserved. These should be 301 permanent re-directs. If there were a second QS variable, I could be appended or ignored.

I can't "show my code" because I don't know where to start. I've seen plenty of apache mod_rewrite q/a and samples, but none that help me in this specific situation.

I re-built this site on Wordpress and just named each page similar to how it was linked before, figuring I'd be able to do the re-directs later. That "later" is now.

Alternative solution: I could edit index.php and add a location header for each of the old pages, or do similar in .htaccess instead of trying to do the pattern match / replace, but I still need help dealing with these Query Strings.

TecBrat
  • 3,643
  • 3
  • 28
  • 45
  • "I'd like to re-write urls of this style:" - Judging by the remainder of your question, you require a redirect, not a "re-write". (A rewrite is where the URL does not change.) To clarify, this is just a one-way redirect? – MrWhite Jul 25 '17 at 16:55
  • @MrWhite Correct, I want the URL to update and the browser to display the new page. My Googling suggested that `redirect` uses `mod_alias` and does not consider the QS, and so I needed to use `mod_rewrite`. The dupe target suggested by Croises might be helpful, but I'll have to take some time to carefully read through it. – TecBrat Jul 25 '17 at 17:03
  • That "dupe question" is a bit overkill IMO unfortunately - I think the others were perhaps misled by the use of the word "re-write" - since your question does at first appear to be about URL-rewriting and implementing "pretty URLs". Consider re-asking your question over on Pro Webmasters: https://webmasters.stackexchange.com/ – MrWhite Jul 25 '17 at 17:12
  • Thank you @Mr.White. I might do that in a moment. – TecBrat Jul 25 '17 at 17:24

0 Answers0