Friendly url
http://pt.com/sicsdev/ln10/qttracksubcampaign
Original URL.
http://pt.com/sicsdev/trakk/lnk/index.php?ctype=1&cparm=0&cname=qttracksubcampaign
This URL rewrite is done in .htaccess file. Code that helped to do this is
RewriteRule
-----------------------------------------------------------------------------------------------------------
RewriteEngine On
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)/$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
------------------------------------------------------------------------------------------------------------
In this many things I had learned
1.In the friendly url there is a parameter In10. From this parameter ctype and cparm value is obtained.
How its possible?
In this parameter In10, prefix part In will be static. So with the help of static value its possible to get succeeding values using regular expression. Check RewriteRule to find it out
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
In the above rule following the static parameter value(In),([0-6]) will give first dynamic parameter value $1 also it limits value of parameter from 0 to 6.([0-2]) will give second dynamic parameter value $2 also it limits value of parameter from 0 to 2.Succeeding slash(/) is mentioned for adding third parameter.
([a-zA-Z0-9-\_]+) will give third parameter value $3.
We can pass the obtained parameter value to the original URL like ?ctype=$1&cparm=$2&cname=$3
2. ([0-6]) using this regular expression will limit parameter value.
3. If we use all the regular expression to receive parameter value in the RewriteRule at once as above then its mandatory to supply all the parameter through URL.
Eg: Lets consider two url to understand
URL 1: Need to pass two parameter at once
Friendly Url -> www.eg.com/type/id
Orginal Url -> www.eg.com/edit.php?t=type&id=id
RewriteRule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ edit.php?t=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ edit.php?t=$1&id=$2
In the above the case two parameter is mandatory at once. So can use above code at once for both parameter value.
URL 2: Need to pass two parameter. But both the parameters are not mandatory.
Friendly Url -> www.eg.com/type/id
Orginal Url -> www.eg.com/edit.php?t=type&id=id
RewriteRule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ edit.php?t=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ edit.php?t=$1
//Second Parameter
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ edit.php?t=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ edit.php?t=$1&id=$2
In the above the case two parameter is not mandatory at once. So need to use rewrite Url for both the parameters.
http://pt.com/sicsdev/ln10/qttracksubcampaign
Original URL.
http://pt.com/sicsdev/trakk/lnk/index.php?ctype=1&cparm=0&cname=qttracksubcampaign
This URL rewrite is done in .htaccess file. Code that helped to do this is
RewriteRule
-----------------------------------------------------------------------------------------------------------
RewriteEngine On
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)/$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
------------------------------------------------------------------------------------------------------------
In this many things I had learned
1.In the friendly url there is a parameter In10. From this parameter ctype and cparm value is obtained.
How its possible?
In this parameter In10, prefix part In will be static. So with the help of static value its possible to get succeeding values using regular expression. Check RewriteRule to find it out
RewriteRule ^ln([0-6])([0-2])/([a-zA-Z0-9-\_]+)$ ./trakk/lnk/index.php?ctype=$1&cparm=$2&cname=$3
In the above rule following the static parameter value(In),([0-6]) will give first dynamic parameter value $1 also it limits value of parameter from 0 to 6.([0-2]) will give second dynamic parameter value $2 also it limits value of parameter from 0 to 2.Succeeding slash(/) is mentioned for adding third parameter.
([a-zA-Z0-9-\_]+) will give third parameter value $3.
We can pass the obtained parameter value to the original URL like ?ctype=$1&cparm=$2&cname=$3
2. ([0-6]) using this regular expression will limit parameter value.
3. If we use all the regular expression to receive parameter value in the RewriteRule at once as above then its mandatory to supply all the parameter through URL.
Eg: Lets consider two url to understand
URL 1: Need to pass two parameter at once
Friendly Url -> www.eg.com/type/id
Orginal Url -> www.eg.com/edit.php?t=type&id=id
RewriteRule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ edit.php?t=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ edit.php?t=$1&id=$2
In the above the case two parameter is mandatory at once. So can use above code at once for both parameter value.
URL 2: Need to pass two parameter. But both the parameters are not mandatory.
Friendly Url -> www.eg.com/type/id
Orginal Url -> www.eg.com/edit.php?t=type&id=id
RewriteRule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ edit.php?t=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ edit.php?t=$1
//Second Parameter
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ edit.php?t=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ edit.php?t=$1&id=$2
In the above the case two parameter is not mandatory at once. So need to use rewrite Url for both the parameters.
0 comments:
Post a Comment