Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. URL rewriting with pure php and .htaccess

URL rewriting with pure php and .htaccess

Scheduled Pinned Locked Moved Web Development
phpapachedatabasemysqlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    partapsingh
    wrote on last edited by
    #1

    I am using php and mysql for one of my project. I have two pages as:
    index.php
    and packages.php

    I am sending id and packagename from index.php using get method and package.php is retriving it and displaying the corresponding values.

    Here is the way I am receiving the value in package.php

    $getpackage = $_GET["package"];

    list($packageid, $packagename) = explode(":",$getpackage);
    $url = strtolower(str_replace(' ', '-', $packageid)) . '-' . $packagename;

    and here is my .htaccess file code

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)$ $1.php [NC]
    RewriteRule ^package/([A-Za-z0-9_]+)/?$ package?$getpackage=$1 [QSA]

    and here is the browser url output

    [^]

    My requirement is abc/package/1/Himachal Main or ../1/Himachal-Main I have tried many ways but i m not able to accomplish this. Leads will be highly appreciated

    L 1 Reply Last reply
    0
    • P partapsingh

      I am using php and mysql for one of my project. I have two pages as:
      index.php
      and packages.php

      I am sending id and packagename from index.php using get method and package.php is retriving it and displaying the corresponding values.

      Here is the way I am receiving the value in package.php

      $getpackage = $_GET["package"];

      list($packageid, $packagename) = explode(":",$getpackage);
      $url = strtolower(str_replace(' ', '-', $packageid)) . '-' . $packagename;

      and here is my .htaccess file code

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^([^.]+)$ $1.php [NC]
      RewriteRule ^package/([A-Za-z0-9_]+)/?$ package?$getpackage=$1 [QSA]

      and here is the browser url output

      [^]

      My requirement is abc/package/1/Himachal Main or ../1/Himachal-Main I have tried many ways but i m not able to accomplish this. Leads will be highly appreciated

      L Offline
      L Offline
      luplup
      wrote on last edited by
      #2

      So first, write the right rewritten url you want in the <a> <a href="http://localhost/abc/package/1/Himachal-Main"> And then the right rewriting rule is something like this: RewriteRule ^abc/package/([0-9]+)/([0-9a-zA-Z-]+)$ /abc/package.php?id=$1&name=$2 [L] So it seem you have to add new get var with the id of the package, to create the /1/

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups