Htaccess [SOLVED]: Re-Routing Query String in PHP

Htaccess [SOLVED]: Re-Routing Query String in PHP

Home Forums htaccess Htaccess [SOLVED]: Re-Routing Query String in PHP

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36965

    Anonymous

    QuestionQuestion

    I have a website that has many URLs that look like this:

    https://www.website.com/view?id=56
    https://www.website.com/category?name=music
    

    Which I would like to look like this:

    https://www.website.com/view/56
    https://www.website.com/category/music
    

    This website is deep into development and it is too late to switch to a framework that makes this simpler.

    My question is: What is the simplest way to do this (again, without using Klien or Composer, or any other framework-type things)? Perhaps something in .htaccess or something along those lines.

    Thanks!
    Eric

    #36966

    Anonymous

    Accepted AnswerAnswer

    You can enable mod_rewrite in your apache config and rewrite what you want with some rules.

    Try this ones:

    RewriteEngine on
    RewriteRule ^view/([0-9-]+)/?$ view?id=$1 [NC]
    RewriteRule ^category/([A-Za-z0-9-]+)/?$ category?name=$1 [NC]
    

    Source: https://stackoverflow.com/questions/48016598/re-routing-query-string-in-php
    Author: jeprubio
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.