Page 1 of 1

Execute .php to .html

Posted: Thu Jun 05, 2014 9:45 pm
by loveme
Hi... I want php file shown in browser as .HTML or like folder. Here I explain:
I have php code in (index.php) as <a href="cat.php?Id=$id"> something like this.Now When user click the link it show in browser as it be,like ...cat.php?Id=3 . But I want here , when user go to(by click) cat.php?id=$id the browser show the URL as ...cat/3.HTML or ...cat/3

Cat = SQL column name
Id= SQL 'cat' fields.
How do I do this...
Thanks in advance...

Re: Execute .php to .html

Posted: Thu Jun 05, 2014 11:51 pm
by requinix
You can't show the user a different URL than the one they went to.

The subject is called "URL rewriting". You instruct Apache to rewrite "/cat/3.html" (what the user sees) to "cat.php?id=3" (what your PHP code actually needs).
Learn a bit about it before you continue, and then the following won't look so cryptic:

Code: Select all

RewriteEngine on
# Turn /cat/#.html to cat.php?id=#
RewriteRule ^/?cat/(\d+)\.html$ cat.php?id=$1 [L,QSA]

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 2:12 pm
by loveme
Hi... Thank you. I am learning this... I can achieve this type now. What should I do if the same think as cat.php?Id=3&pg=2

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 4:19 pm
by requinix
Link to /cat/3.html?pg=2.

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 4:29 pm
by loveme
Hi...I just improved ( I think ) ... Here I removed .HTML now it looks as local host/3 for local host/cat.php?Id=2 with htaccess Rewrite rule ^/?(\d+) $ cat.php?Id=$1 [L,QSA] . Now I want to show cat.php?Id=3&pg=5 to local host/3/5

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 4:41 pm
by Celauran
/cat/3/page/5 is a far more meaningful URI than /3/5

That said

Code: Select all

^/?(\d+)/(\d+)/? cat.php?id=$1&pg=$2
You may be interested in this htaccess tester

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 4:59 pm
by loveme
Works fine. But next page URL take the previous no.
Ex. local host/cat/3/page/1 when I click 2 page it show the URL as local host/cat/3/pg/cat/3/pg/2 how can I rectify this

Re: Execute .php to .html

Posted: Sat Jun 14, 2014 6:58 pm
by Celauran
Sounds like you're using relative instead of absolute links. Try adding a leading slash.

Re: Execute .php to .html

Posted: Sun Jun 15, 2014 12:49 am
by loveme
Oh...thanks... Can we use it with relative links ...