URL rewriting with pure php and .htaccess
-
I am using php and mysql for one of my project. I have two pages as:
index.php
and packages.phpI 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
-
I am using php and mysql for one of my project. I have two pages as:
index.php
and packages.phpI 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
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/