.htaccessurlrewriting

.htaccess - URL rewriting - advanced


I wondered how to rewrite a simple URL into a fancy one, but with following condidions:

Simple URL (url that will be referred at in the end) : http://www.example.com/index.php?page_id={ID}

Advanced URL that will be public: http://www.example.com/this-text-doesnt-care-here-could-be-anything.{ID}/

So we have to look for the number after the dot - this is the only thing we care about. The typed text is supposed to be changed and would redirect to the same page - even if changed. So we have to filter the ID at the and of this text out and finally 'redirect' this url internally. But how the code looks like? It would be really nice if you could post the code below! I really do not have an idea.

Thanks a lot in advance.

Have a good day!

Sincerely, WladHD


Solution

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

    RewriteEngine On
    
    RewriteRule ^.+\.(\d+)/?$ index.php?page_id=$1 [L,QSA]