I want to rewrite CMS page url to custom url.

For eg. CMS page url is "/result/?q=test" and rewrite url should be "/demo/test"

For this I'm trying to below htaccess rule

RewriteRule ^demo/?$ /result/?q=$1 [QSA,L]

Url "/result/?q=test" is working, but the url "/demo/test" is showing 404 not found.

What rule should I use this?

1 Answer 1


Actually all request redirected to the index.php which internally uses $_SERVER['REQUEST_URI'] to determine what page or resource actually requested. Above htaccess will just redirect the request to /result/ but to index.php $_SERVER['REQUEST_URI'] will remain /demo/test

What you can do is add below code to your index.php it will do the trick

   $_SERVER['REQUEST_URI'] = '/result/?q='.str_replace('/demo/', '', $_SERVER['REQUEST_URI']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.