Pergunta

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?

Foi útil?

Solução

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

if(strpos($_SERVER['REQUEST_URI'],'/demo/')!==FALSE)
{
   $_SERVER['REQUEST_URI'] = '/result/?q='.str_replace('/demo/', '', $_SERVER['REQUEST_URI']);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top