0

i develop an application using php mysql. below is example of my link.

http://www.domain.com/index.php?page=product&product_id=123&type=virtual


http://www.domain.com/index.php?page=checkout&product_id=456&type=download

i would like to change it to :

http://www.domain.com/product/123/virtual/
http://www.domain.com/checkout/456/download/

I know it can change using rewrite mode on .htaccess, but did i need to rewrite to htaaccess when i create a new page?

wordpress have 7 line (i think) on their .htaccess file.

Can i get a global coding on .htaccess to achive my goal?? im very lazy to create a new rewrite rule everytime i create a new page. i just need to follow this rule

http://www.domain.com/page/parameter/parameter/...
  • You can map your pretty urls to your existing ones. You'll have to change your existing links, to match the pretty ones within your application. Assuming you want the pretty urls as the canonical form. Adding additional rules is easy, but it may become a management headache mapping. I don't think your example buys much in terms of usability. – Progrock May 11 '16 at 12:19
  • @Progrock sorry. i dont understand what are you explaining to me. did my application url are hard to rewrite? – Shaiful Ezani May 11 '16 at 12:23
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Croises May 11 '16 at 12:45
  • Is the site already live with the old style links? – Progrock May 24 '16 at 08:47

1 Answers1

0

You need to redirect all requests for non existing files to index.php file

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if file or directory exests, use it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# else send request to index.php
RewriteRule . index.php

Then, in index.php you parse URI and show the necessary page.

DimaS
  • 571
  • 2
  • 5
  • 19
  • thanks for your time. Did i just need to copy paste your code on my htaccess file then all my page have pretty link? – Shaiful Ezani May 11 '16 at 12:26
  • Besides .htaccess, you need a logic in index.php to route to right page. – DimaS May 11 '16 at 12:30
  • yes i already route the page on index using if($_GET['page'] == 'product'){ include 'product.php'; } – Shaiful Ezani May 11 '16 at 12:35
  • 1
    For example, if URL is `http://www.domain.com/product/123/virtual/` in index.php you can parse it in array by this way: `$route = explode( '/' , $_SERVER['REQUEST_URI'])`. Now `$route[0] == product, $route[1] == 123, $route[2] == virtual` and then you code: `if($route[0] ... ` – DimaS May 11 '16 at 12:43
  • alright. i get it. so i just need to past your code on htaccess then route the page. when i need the get parameters, i just use explode the url right? – Shaiful Ezani May 12 '16 at 02:42