0

I was trying to rewrite the query of a page on my site so that it wouldn't be exposed, but no matter what I write, the server doesn't seem to be able to rewrite the URL, even with the regex working perfectly.

Example: /news/new.html?id=nEJjeqwjeKBEwkqbjBKEJqwbkjQWEB

Target: /news/nEJjeqwjeKBEwkqbjBKEJqwbkjQWEB or /news/new

When I try to remove the query in .htacess it doesn't seem to work at all. I already tried using this code for example:

RewriteCond %{QUERY_STRING} ^(.*)&?id=[^&]+&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L]

But nothing happens, even putting the exact same url that is in the regex. I'm pretty new to website development and I have almost no knowledge of apache, can anyone help me?

Edit: I've already tried several codes here from Stackoverflow, none seem to work.

  • Does this answer your question? [.htaccess rewrite query string as path url](https://stackoverflow.com/questions/69704005/htaccess-rewrite-query-string-as-path-url) – Zak Jul 05 '22 at 20:20
  • I put the exact same code snippet in my .htaccess (of course, changing action to id) and it didn't work, unfortunately – DoutorWhite Jul 05 '22 at 20:25
  • Do you have `mod_rewitre` enabled in Apache? Are you sure your `htaccess` file is even being read? (Throw random characters in the file and try to illicit a 500 error) – Zak Jul 05 '22 at 20:30
  • Yes, it is being read and enabled, so much so that I use it to remove the extensions from the pages and force https on the page, which makes it strange that these codes don't work. – DoutorWhite Jul 05 '22 at 20:37

0 Answers0