Name a page as abc.htm while actual page is word.php?w=abc
Question posted by: hsriat
( Expert)
on
March 27th, 2008 06:25 PM
I have seen this many sites including theScripts, that page is actually .php with some get parameter, but the page can be found at an .htm page with no get parameter.
How can that be done?
eg. If you want to see a word say girl, and the PHP page showing this word is word.php?w=girl.
I want to access the same page at girl.htm
Wikipedia does something similar.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
March 27th, 2008 06:56 PM
# 2
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
The only reason to do this is to make it a lot easier to add new pages. Take the following and call that word.php
Code: ( text )
<?php $newpage=$_GET['w'].'htm'; if (file_exists($newpage)) header ("location: $newpage"); else echo "page for $_GET['w'] does not exist"; ?>
and this one and call that girl.htm
Code: ( text )
<body> This a a girl </body>
Now when I want to add a word e.g. boy, all I have to do is make some html file with the name 'boy.htm' and call it using word.php?w=boy.
The actual code in word.php is a bit more complicated, but this is a very simplified version. I have used this to allow my users to add text pages (.htm) to the site.
Was this the answer you were looking for?
Ronald
__________________
RTFM is an almost extinct art form.
Last edited by ronverdonk : March 27th, 2008 at 07:27 PM.
Reason: code typo
|
|
March 27th, 2008 08:16 PM
# 3
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Thanks, but I want the completely opposite thing.
I mean I have a page word.php which reads the get parameter (w) and searches the database for that unique id (w) in a table, and displays the result.
So to see details of any x word, which is in the database, word.php?w=x would work.
But I want the result to be shown when the user types x.htm, instead of word.php?w=x
This is what is done in Wikipedia, and here in theScripts too. This is actually very useful to get your site in the search engine's search results.
A good familiar example is here...
word.php?w=php
php.htm
|
|
March 27th, 2008 08:24 PM
# 4
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
I believe that's a htaccess job, no?
Code: ( text )
RewriteEngine On # start engine RewriteRule ^([a-zA-Z0-9])\.html$ word.php?w=$1
Not sure whether that is syntactically correct, but it's the right logic.
;)
Regards.
|
|
March 27th, 2008 08:33 PM
# 5
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by markusn00b
I believe that's a htaccess job, no?
Code: ( text )
RewriteEngine On # start engine RewriteRule ^([a-zA-Z0-9])\.html$ word.php?w=$1
Not sure whether that is syntactically correct, but it's the right logic.
;)
Regards.
|
Even I think you are right, but need to try it first.
And dude you still didn't find a solution to that scalability issue!
Regards,
Harpreet
|
|
March 27th, 2008 10:19 PM
# 6
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by hsriat
Even I think you are right, but need to try it first.
And dude you still didn't find a solution to that scalability issue!
Regards,
Harpreet
|
Ah, that's a shame.. and you call yourself an expert ;)
Regards
|
|
March 28th, 2008 07:59 AM
# 7
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by markusn00b
Ah, that's a shame.. and you call yourself an expert ;)
Regards
|
I can't be blamed! I'm a JS expert... you the PHP expert B-)
Regards
Harpreet
|
|
March 28th, 2008 01:53 PM
# 8
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by hsriat
I can't be blamed! I'm a JS expert... you the PHP expert B-)
Regards
Harpreet
|
Have you had any luck with the .htaccess?
I must do something right!!!!!
Regards ;)
|
|
March 28th, 2008 02:49 PM
# 9
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by markusn00b
Have you had any luck with the .htaccess?
I must do something right!!!!!
Regards ;)
|
I didn't try it yet.
Had many other things to do. :(
Will tell you if it worked.
Regards
|
|
March 29th, 2008 02:27 PM
# 10
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
If you have access to the Apaches config file then all you need to do is tell Apache (assuming your server is Apache) to parse HTML files as PHP.
This is how its done:
Code: ( text )
AddType application/x-httpd-php .html
In fact you can have ANY file extension for eg.
Code: ( text )
AddType application/x-httpd-php .made_up_ext
The other way, as was mentioned earlier is .htaccess
However, you should avoid the .htaccess method as its extremely resource hungry. Thats why some shared hosting companies dont allow it to be used.
Hope this helps,
Regards
|
|
March 29th, 2008 04:45 PM
# 11
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by aktar
If you have access to the Apaches config file then all you need to do is tell Apache (assuming your server is Apache) to parse HTML files as PHP.
This is how its done:
Code: ( text )
AddType application/x-httpd-php .html
In fact you can have ANY file extension for eg.
Code: ( text )
AddType application/x-httpd-php .made_up_ext
The other way, as was mentioned earlier is .htaccess
However, you should avoid the .htaccess method as its extremely resource hungry. Thats why some shared hosting companies dont allow it to be used.
Hope this helps,
Regards
|
That isn't answering his question (although it is still interesting).
Hsriat wants the urls to be seen as one thing but be read as another, i.e. url rewriting (also know as: 'pretty urls').
regards :)
|
|
March 30th, 2008 01:00 PM
# 12
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Oppsy, I see it now :)
With this rewrite concept, would you have to set a rule for every page you wish to rewrite?
|
|
March 31st, 2008 08:47 AM
# 13
|
Re: Name a page as abc.htm while actual page is word.php?w=abc
Quote:
Originally Posted by aktar
Oppsy, I see it now :)
With this rewrite concept, would you have to set a rule for every page you wish to rewrite?
|
writing it for every page, kind of defeats the whole purpose.
what's wrong with you?
Your dancing around two issues: hiding extensions and pretty URLs.
they acomplish two different things.
Not the answer you were looking for? Post your question . . .
183,939 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top PHP Forum Contributors
|