0

I am looking to rewrite a URL from current dynamic structure..

www.domain.com/news/news.php?news=id

to this new

www.domain.com/?p=id

the id is a dynamically number-based id.

I have tried multiple solutions for this, but it seems like I am not good enough at htaccess, because I can't get it to work.

Anyone with a good solution?

1 Answer 1

1

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)news=([^&]+) [NC]
RewriteRule ^news/news\.php$ /?p=%1 [L,NC]
Sign up to request clarification or add additional context in comments.

2 Comments

ahh. very close to a solution there :) Thanks. But for some reason it seems like I am getting this at the end of my new url? ?news=id (where id displays the number)
That should not happen with this rule. Do you have QSA flag by any chance?

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.